Skip to content

Commit 89b0f58

Browse files
committed
Reword
1 parent 6bcb784 commit 89b0f58

File tree

1 file changed

+16
-26
lines changed

1 file changed

+16
-26
lines changed

components/process.rst

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -410,46 +410,36 @@ instead::
410410
);
411411
$process->run();
412412

413-
Executing a PHP child processes with the same configuration
414-
-----------------------------------------------------------
413+
Executing a PHP Child Process with the Same Configuration
414+
---------------------------------------------------------
415415

416416
.. versionadded:: 6.4
417417

418-
The ``PhpSubprocess`` helper was added in Symfony 6.4.
418+
The ``PhpSubprocess`` helper was introduced in Symfony 6.4.
419419

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``.
424425

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::
426429

427430
use Symfony\Component\Process\Process;
428431

429432
class MyCommand extends Command
430433
{
431434
protected function execute(InputInterface $input, OutputInterface $output): int
432435
{
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
433439
$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`::
446440

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
453443
$childProcess = new PhpSubprocess(['bin/console', 'cache:pool:prune']);
454444
}
455445
}

0 commit comments

Comments
 (0)