Home >Backend Development >PHP Tutorial >php-fpm often appears 502 solution_PHP tutorial
For more, please support: www.Bkjia.com
Recently, nginx often gets 502. The best way to solve 502 is to restart php-fpm.
It is still troublesome to restart manually. The best thing is to throw it into the shell.
vim restart-php-fpm.sh
#!/bin/sh SERVICE='php-fpm' #if ps ax | grep -v grep | grep $SERVICE > /dev/null if netstat -anp | grep 9000 > /dev/null then echo $SERVICE service running, everything is fine else echo $SERVICE is not running service php-fpm start fiI tested it on the local virtual machine and it worked. I threw it on the server. It turned out that when I got 502, it was not that php-fpm had no process, but that php-fpm was dead.
vim restart-php-fpm.sh
#!/bin/bash MY_URL=http://www.webyang.net RESULT='curl -I $MY_URL | grep HTTP/1.1 502\' if [ -n $RESULT ]; then #如果502则会执行这里的内容,随便加或改 killall -9 php-cgi service php-fpm restart fiIn this case, it is still manual. If you need it automatically, add it to the crontab yourself.
Or write a shell infinite loop and execute it after a period of time.