PHP Script monitors nginx 502 error and automatically restarts PHP-FPM,NGINXPHP-FPM
Recently the server occasionally appeared Nginx 502 bad Gateway, if in the computer next to good, if midnight or go out, how to do?
No problem, write a script to detect the status of the service, found an exception, automatic restart.
Automatic Restart Script:
Copy the Code code as follows:
<?php
$url = ' Http://blog.rebill.info ';
$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 ();
}
}
The principle is to get the HTTP header with Curl and find the 502 status code to execute the command to restart the PHP-FPM.
URLs and CMD are changed to their own according to the actual situation. Then put it in the crontab one minute to execute it.
Copy the Code code as follows:
*/1 * * * */usr/bin/php/root/crontab/nginx502.php
Done!
http://www.bkjia.com/PHPjc/998803.html www.bkjia.com true http://www.bkjia.com/PHPjc/998803.html techarticle PHP Script monitors nginx 502 error and automatically restarts PHP-FPM,NGINXPHP-FPM the recent server occasionally appears Nginx 502 bad Gateway, if it is OK next to the computer, if midnight or out, ...