hello, i need to restart my php program when the memory of the program exceeds 500 mb ... it can be done by any script in php or in shell ????
+1
A:
Run your PHP script like this:
php -d "memory_limit=500M" myscript.php
And do it forever:
while true; do php -d "memory_limit=500M" myscript.php; done
strager
2010-08-01 14:52:57
heh... good trick :)I would use daemon for this...
confiq
2010-08-01 15:02:59
i have written an shell script start.sh like thisphp -d "memory_limit=500M" myscript.phpwhile true; do php -d "memory_limit=500M" myscript.php; doneonce i run the program i am getting segmentation fault error....
Ram
2010-08-01 15:07:49
@Ram, The script should only contain the second line. I was just showing the natural progression to the solution in my answer. I don't see how you would get a segfault; this would be a bug in PHP which you may want to report. (How are you normally executing the PHP script?)
strager
2010-08-01 15:10:05
@strager ,it didnt restart the program the memory is still increasing.... if i use "while true; do php -d "memory_limit=500M" myscript.php; done"
Ram
2010-08-01 15:27:47
@Ram, When PHP reaches the memory limit, it raises a fatal error and quits the PHP script. Are you absolutely sure PHP is using more than 500MB?
strager
2010-08-01 16:27:32
How does your PHP script hit 500 MB of memory usage so quickly?
BoltClock
2010-08-01 16:48:27
A:
Whenever I deal with long-running programs, I like to include some basic tools for checking whether they are active, what errors they are creating, etc. Here's a quick script I run with cron to make sure that my gearman workers are running.
$program = 'program.php';
// Run the cmd to get list of running programs
exec( "ps aux | grep $program | awk '{print $12}'", $output );
if( count($output) == 0 )
exec( "php $program > /dev/null &" );
Of course, you may not want the output of your script sent to /dev/null. In fact, if you're having problems with memory usage, you may want to use the >>
operator to capture your script's output in a makeshift log.
Chris Henry
2010-08-01 16:46:48