-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Process] Introducing a new PhpSubprocess
handler
#48485
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
Conversation
src/Symfony/Component/Process/Tests/OutputMemoryLimitProcess.php
Outdated
Show resolved
Hide resolved
PhpSubprocess
handler
Pinging @johnstevenson as he authored most of the xdebug-handler code. Feel free to ignore if not interested though :) |
For the record: Fabien documented how to write CHANGELOG.md files here: symfony/symfony-docs#14830 |
I guess this will work as well as Proper attribution for the |
Sure, would you mind adding a code review/suggestion as to how you'd like to have this being done? Might also just add yourself as an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be useful. Here are some comments.
src/Symfony/Component/Process/Tests/OutputMemoryLimitProcess.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas everything addressed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor things and good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but @Toflar, you need to rebase to remove the merge commit.
b89710f
to
9364391
Compare
9364391
to
f682a29
Compare
Rebased and addressed the remaining reviews. |
Thank you @Toflar. |
Do we really need this new class? The failing tests suggest otherwise. |
We want this feature yes. The tests are with sigchild enabled. Something to investigate. Same for the open_basedir-related failures. |
…cutable (GromNaN) This PR was merged into the 6.4 branch. Discussion ---------- [Process] Fix OutputMemoryLimitProcess.php cannot be executable | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT PHP files cannot be executable without shebang. File introduced by #48485 Note that there is no other executable .php file. Commits ------- 09992b7 PHP files cannot be executable without shebang
Description ----------- Unfortunately, our `ProcessUtil` service currently cannot be used with custom flags such as `-d memory_limit=-1`. You currently have to do something like this: ```php $process = $this->processUtil->createSymfonyConsoleProcess('...'); $reflection = new \ReflectionClass($process); $commandline = $reflection->getProperty('commandline'); $commandline = $commandline->getValue($process); array_splice($commandline, 1, 0, ['-d', 'memory_limit=-1']); $process = new Process($commandline); return $this->processUtil->createPromise($process); ``` First, I thought we could add a new `createSymfonyConsoleProcessWithAdditonalDirectives()` but then, as soon as you want to use something else than `new Process()` (e.g. my new [`new PhpSubprocess()`](symfony/symfony#48485)) then this wouldn't work either. So I thought it would be best to expose the console path and binary path as getters. Commits ------- 7e3ba37 Allow to re-use the ProcessUtil data
Description ----------- Unfortunately, our `ProcessUtil` service currently cannot be used with custom flags such as `-d memory_limit=-1`. You currently have to do something like this: ```php $process = $this->processUtil->createSymfonyConsoleProcess('...'); $reflection = new \ReflectionClass($process); $commandline = $reflection->getProperty('commandline'); $commandline = $commandline->getValue($process); array_splice($commandline, 1, 0, ['-d', 'memory_limit=-1']); $process = new Process($commandline); return $this->processUtil->createPromise($process); ``` First, I thought we could add a new `createSymfonyConsoleProcessWithAdditonalDirectives()` but then, as soon as you want to use something else than `new Process()` (e.g. my new [`new PhpSubprocess()`](symfony/symfony#48485)) then this wouldn't work either. So I thought it would be best to expose the console path and binary path as getters. Commits ------- 7e3ba373 Allow to re-use the ProcessUtil data
This PR provides a new
PhpSubprocess
handler which can be used to run PHP commands and taking over their parent PHP configuration. This is not super easy in PHP because the only way to do that requires a temporaryini
file.That's why I see perfect fit for it in the
symfony/process
component as it solves a common issue.The code is heavily inspired/copied from
composer/xdebug-handler
where the requirement is similar - being able to have a child process/subprocess that takes over the config of the parent process. Hence, mentioning @Seldaek here.Basically, this can be very useful in Symfony when you want to run
bin/console other-command
from within Symfony.Let's imagine a general cronjob command that is supposed to delegate to other commands like this (simplified a lot):
Now if you run the cronjob command itself with dynamic configuration like so:
php -d memory_limit=256M bin/console run-cronjobs
, the subprocesses (cache:pool:prune
etc.) will not be limited to256M
because they themselves will start a completely new PHP process which will take the default PHP settings again.This affects everything, not just
memory_limit
but also runtime, extensions etc. You name it.Oftentimes, however, that's not what you want. You'd like to have the children have the same restrictions as your parent process.
With this new handler, all you have to do is to use
PhpSubprocess
instead ofProcess
and it will create a temporaryini
file taking over all the settings of the parent process. Done 😊The current design is pretty straightforward without any extension points just yet (no way to fetch the
ini
files separately etc.). Also, it could maybe do with some more tests for theini
parsing but at this stage I would like to ask if this would even be a welcomed addition to Symfony or not 😊