@@ -410,46 +410,36 @@ instead::
410
410
);
411
411
$process->run();
412
412
413
- Executing a PHP child processes with the same configuration
414
- -----------------------------------------------------------
413
+ Executing a PHP Child Process with the Same Configuration
414
+ ---------------------------------------------------------
415
415
416
416
.. versionadded :: 6.4
417
417
418
- The ``PhpSubprocess `` helper was added in Symfony 6.4.
418
+ The ``PhpSubprocess `` helper was introduced in Symfony 6.4.
419
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 ``.
420
+ When you start a PHP process, it uses the default configuration defined in
421
+ your ``php.ini `` file. You can bypass these options with the ``-d `` command line
422
+ option. For example, if ``memory_limit `` is set to ``256M ``, you can disable this
423
+ memory limit when running some command like this:
424
+ ``php -d memory_limit=-1 bin/console app:my-command ``.
424
425
425
- Problem solved. However, let's assume you have an ``app:my-command `` that itself again, starts a PHP child process::
426
+ However, if you run the command via the Symfony ``Process `` class, PHP will use
427
+ the settings defined in the ``php.ini `` file. You can solve this issue by using
428
+ the :class: `Symfony\\ Component\\ Process\\ PhpSubprocess ` class to run the command::
426
429
427
430
use Symfony\Component\Process\Process;
428
431
429
432
class MyCommand extends Command
430
433
{
431
434
protected function execute(InputInterface $input, OutputInterface $output): int
432
435
{
436
+ // the memory_limit (and any other config option) of this command is
437
+ // the one defined in php.ini instead of the new values (optionally)
438
+ // passed via the '-d' command option
433
439
$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
440
447
- use Symfony\Component\Process\PhpSubprocess;
448
-
449
- class MyCommand extends Command
450
- {
451
- protected function execute(InputInterface $input, OutputInterface $output): int
452
- {
441
+ // the memory_limit (and any other config option) of this command takes
442
+ // into account the values (optionally) passed via the '-d' command option
453
443
$childProcess = new PhpSubprocess(['bin/console', 'cache:pool:prune']);
454
444
}
455
445
}
0 commit comments