-
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #37519 [Process] allow setting options esp. "create_new_conso…
…le" to detach a subprocess (andrei0x309) This PR was merged into the 5.2-dev branch. Discussion ---------- [Process] allow setting options esp. "create_new_console" to detach a subprocess Process.php to include support for create_new_console (Windows ONLY) | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | #36583 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Based on this issue: symfony/symfony#36583 I created a quick repo [ https://github.com/andrei0x309/tets_sym_proc]( https://github.com/andrei0x309/tets_sym_proc) to illustrate how this feature can be used, it essentially lets you run something even if your main script has terminated. It is useful if you want to create something like `new Process(['php', 'script_with_long_execution_time.php']);` This was impossible to do on windows until the **create_new_console** flag was added in PHP 7.4.4. With this feature Process can be used like this: ``` // Start a process and detach form it on Win only $process = new Process(['php', 'worker.php']); $process->setOptions(["create_new_console" => true]); // New method I added $process->disableOutput(); $process->start(); Process Class behavior will never change if the user doesn't use setWinOptions() ``` Commits ------- e9ab235b66 [Process] allow setting options esp. "create_new_console" to detach a subprocess
- Loading branch information
Showing
4 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Process\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @author Andrei Olteanu <[email protected]> | ||
*/ | ||
class CreateNewConsoleTest extends TestCase | ||
{ | ||
public function testOptionCreateNewConsole() | ||
{ | ||
$this->expectNotToPerformAssertions(); | ||
try { | ||
$process = new Process(['php', __DIR__.'/ThreeSecondProcess.php']); | ||
$process->setOptions(['create_new_console' => true]); | ||
$process->disableOutput(); | ||
$process->start(); | ||
} catch (\Exception $e) { | ||
$this->fail($e); | ||
} | ||
} | ||
|
||
public function testItReturnsFastAfterStart() | ||
{ | ||
// The started process must run in background after the main has finished but that can't be tested with PHPUnit | ||
$startTime = microtime(true); | ||
$process = new Process(['php', __DIR__.'/ThreeSecondProcess.php']); | ||
$process->setOptions(['create_new_console' => true]); | ||
$process->disableOutput(); | ||
$process->start(); | ||
$this->assertLessThan(3000, $startTime - microtime(true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
echo 'Worker started'; | ||
sleep(3); | ||
echo 'Worker done'; |