Nginx encountered 502 Bad Gateway automatic restart script code

  • 2020-05-06 12:13:25
  • OfStack

The idea is to get the HTTP header with curl, find the 502 status code, and execute the command to restart php-fpm.
 
#!/usr/bin/php 
<!--$url = '//www.jb51.net'; 
$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(); 
} 
} 
--> 

For crontab, please search for Google or refer to the following article
//www.jb51.net/LINUXjishu/19905.html
//www.jb51.net/LINUXjishu/17374.html

Related articles: