PHP exec() use of memory

2020-03-24 19:58发布

问题:

I can't seem to find a definitive answer for this one.

When invoking a shell command using exec() from PHP, does the memory that shell command uses count towards the memory limit that the PHP script is given?

I realise that if the command generates a lot of output, and that output is captured in the $ouput (second) parameter of exec(), then that returned data could blow the PHP memory limit. However, assuming all output is sent to a file, if the exec() command requires 128M of memory to run, should a PHP script with a limit of 64M of memory be able to run it?

<?php
exec('command_using_128M_memory >/dev/null 2>&1');

I'm assuming PHP5.3+

回答1:

The exec() command does not directly count towards the PHP since the process is executed separately not from within the PHP Process. Having said that if you use any output variable with the command they would count towards the limit.

So if you had a file which produced a lot of verbose logging, and you were capturing that logging it would count towards the memory limit.



标签: php memory exec