Nginx 遇到 502 Bad Gateway 自动重启脚本

放到crontab里一分钟执行一次。URL和CMD根据自己的改。

#!/usr/bin/php
$url = 'http://www.diahosting.com';
$cmd = '/usr/local/php/sbin/php-fpm restart';

for($i = 0; $i < 5; $i ++){
$exec = "curl --connect-timeout 3 -I $url 2>/dev/null”;
$res = shell_exec($exec);

if(stripos($res, ’502 Bad Gateway’) !== false){
shell_exec($cmd);
exit();
}
}
?>

至于crontab,请自行Google搜索

来源:http://www.hostloc.com/viewthread.php?tid=19208&page=1#pid235729

© 2010, 酷胖优惠码. 版权所有.

赶紧订阅“酷胖优惠码”,不错过一个省钱的机会!~

Leave a comment

5 Comments.

  1. 不错,有用

  2. :roll: 为啥我看不懂呢~~$exec都没运行$res又怎么得到的?晕晕了

Leave a Reply


[ Ctrl + Enter ]


אורן יומטוב