Description
By default, PHP uses a memory_limit of 128M.
Since Symfony/Process stores all output in private $stdout;
and private $stderr;
, this means that as soon as the output hits 128MB, your PHP script using Symfony/Process will fatally error out with:
[15-Jan-2016 06:31:02 America/New_York] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 131862121 bytes) in /app/myapp/vendor/symfony/process/Process.php on line 815
You can test this pretty quickly by just doing this (assuming you have GNU Coreutils installed):
require("vendor/autoload.php");
use Symfony\Component\Process\Process;
$process = new Process('yes "Hello"');
$process->setTimeout(172800);
$process->run(function ($type, $buffer) {
// do nothing
});
Unfortunately, we assumed that Symfony/Process was already using a temporary buffer for closures, and saw this issue in production. To mitigate the issue for now, we bumped up our memory_limit
, but ideally this should be fixed in Symfony itself.
Since the upper limit on a PHP string itself is 2GB, this also means that Symfony/Process will currently die when the buffer reaches 2GB, no matter what. Here's a sample of that error
[15-Jan-2016 10:16:05 America/New_York] PHP Fatal error: String size overflow in /app/myapp/vendor/symfony/process/Process.php on line 799
In my opinion, registering closure to run
should mean that the entire buffer should not be stored in memory.
Please share your thoughts.