|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-10-12 16:55 UTC] vasilios at betoglou dot com
Description: ------------ I have a script that searches through files on the local system for a particular string and returns the results. The form page does an ajax call to the function page. This uses shell_exec to run the command locally. If, while the command is running, the results get too large, an error like this is thrown: [Thu Oct 12 12:21:49.963798 2017] [:error] [pid 16001] [client 172.19.32.179:50338] PHP Fatal error: Allowed memory size of 41943040 bytes exhausted (tried to allocate 23068704 bytes) in /var/www/html/wp-content/themes/twentyfourteen-child/results.php on line 28, referer: https://<url>/metadata-search/ I upped the memory limit from 512M to 1024M I get an OOM error. I upped the limit to 2048M, no error is logged, but the script just stops as if it had crashed. Any value above ~1400M seems to be causing this issue, where the script returns no results and nothing is logged. If I search for a term that returns smaller results, everything works fine: (find command run CLI for example as to what the script is dealing with) <user>@<host>:~$ find /home/metadata/arl.data/arlindex.xml -type f | xargs grep -E 'host' /dev/null -nr |wc -l 863439 > OOM with memory_limit < ~1400M, script just dies if > ~1400M, no error thrown. <user>@<host>:~$ find /home/metadata/arl.data/arlindex.xml -type f | xargs grep -E 'betoglo' /dev/null -nr |wc -l 11 > WORKS FINE Test script: --------------- $cmd="find $directory$filename -type f | xargs grep -E '$terms' $range /dev/null -nr"; $link=shell_exec($cmd); Expected result: ---------------- I expect to see an OOM error or correct results. Actual result: -------------- I see no OOM error in /var/log/apache/error.log, the script dies with no results. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 22 01:00:01 2025 UTC |
Ok, so I tried taking shell_exec out of the equation by running something simple like this: <?php $var="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; while(true){ $var.=$var; echo memory_get_usage() . "<br>"; } ?> It does throw an OOM error, and if I up the value to 4096M (higher than the value I saw the issue previously), it throws a different OOM error. So you are right, it seems to be a link between shell_exec and memory_limit. Output: 358856 358936 359032 359224 359672 360568 362872 366968 375160 387448 416120 469368 575864 788856 1214840 2066808 3770768 7178640 13994384 27625872 54888848 109414800 218466704 436570512 872778128 1745193360 error.log: [Thu Oct 12 14:21:21.770973 2017] [:error] [pid 29059] [client 172.19.32.179:58966] PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 3489660960 bytes) in /var/www/html/test.php on line 4 Something like this, though, worked fine: <?php $var=""; while(true){ $var.=shell_exec("echo $var"); echo memory_get_usage() . "<br>"; } ?> I.E. it threw an OOM error... so it's not necessarily the shell_exec but what it's doing.