Skip to content

[Process] allow setting options esp. "create_new_console" to detach a subprocess #37519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2020

Conversation

andrei0x309
Copy link
Contributor

@andrei0x309 andrei0x309 commented Jul 7, 2020

Process.php to include support for create_new_console (Windows ONLY)

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets #36583
License MIT
Doc PR symfony/symfony-docs#...

Based on this issue: #36583
I created a quick repo 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()

@andrei0x309 andrei0x309 marked this pull request as draft July 7, 2020 21:33
@andrei0x309 andrei0x309 marked this pull request as ready for review July 7, 2020 22:26
@nicolas-grekas nicolas-grekas added this to the next milestone Jul 8, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests please, eg for the validation of options?

@nicolas-grekas
Copy link
Member

Please also update the CHANGELOG of the component btw.

@xabbuh xabbuh added the Process label Sep 2, 2020
@nicolas-grekas nicolas-grekas changed the title Update Process.php for create_new_console [Process] allow setting options esp. "create_new_console" to detach a subprocess Sep 8, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without create_new_console you can't terminate your main script and let the process run

That's a very good point, it made me change my mind.

I updated the PR to keep only the actually supported option and made create_new_console "detach" the subprocess by closing pipes on both Windows and *nix.
This means we don't need the detach pseudo-option anymore.

PR is good for me as is now, thanks for the discussion.

@fabpot
Copy link
Member

fabpot commented Sep 8, 2020

Thank you @andrei0x309.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants