开发者

shell command to restart an php program [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit t开发者_运维技巧he help center. Closed 10 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜