shell command to restart an php program [closed]
I need to restart my php program when the memory of the program exceeds 500mb. Can it be done by any script in php or in shell?
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
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.
精彩评论