@@ -410,6 +410,50 @@ instead::
410410 );
411411 $process->run();
412412
413+ Executing a PHP child processes with the same configuration
414+ -----------------------------------------------------------
415+
416+ .. versionadded :: 6.4
417+
418+ The ``PhpSubprocess `` helper was added in Symfony 6.4.
419+
420+ When you start a PHP process, it's started using its default ``ini `` settings. Let's assume you have a configured
421+ ``memory_limit `` of ``256M `` in your `php.ini ` and you want to disable it when running your ``bin/console `` script to access
422+ the Symfony console without any memory limit. You can then dynamically override it using the ``-d `` command line option
423+ like so: ``php -d memory_limit=-1 bin/console app:my-command ``.
424+
425+ Problem solved. However, let's assume you have an ``app:my-command `` that itself again, starts a PHP child process::
426+
427+ use Symfony\Component\Process\Process;
428+
429+ class MyCommand extends Command
430+ {
431+ protected function execute(InputInterface $input, OutputInterface $output): int
432+ {
433+ $childProcess = new Process(['bin/console', 'cache:pool:prune']);
434+ }
435+ }
436+
437+ What happens now is that PHP will start the ``bin/console cache:pool:prune `` command with a ``memory_limit `` of ``256M ``. That's
438+ because this is your ``ini `` setting.
439+
440+ If you want to make sure that the child processes inherit the dynamically adjusted configuration as well, there is only one
441+ way to do that: You have to write a temporary ``ini `` file with all the current settings and start the child process using
442+ ``php -c temporary.ini bin/console cache:pool:prune ``.
443+
444+ Doing this yourself can be cumbersome but don't worry, Symfony's got you covered! All you need to do is replace the
445+ usage of ``Process `` with :class: `Symfony\\ Component\\ Process\\ PhpSubprocess `::
446+
447+ use Symfony\Component\Process\PhpSubprocess;
448+
449+ class MyCommand extends Command
450+ {
451+ protected function execute(InputInterface $input, OutputInterface $output): int
452+ {
453+ $childProcess = new PhpSubprocess(['bin/console', 'cache:pool:prune']);
454+ }
455+ }
456+
413457Process Timeout
414458---------------
415459
0 commit comments