PHP-FPM often appear 502 solutions

Source: Internet
Author: User
Tags add fpm

More please support: www.2cto.com


Recently Nginx is often 502, the best way to solve 502 is to restart PHP-FPM.
Manual reboot is still a hassle, and the best thing to do 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
fi
Local virtual machine test a bit, feasible, throw to the server, the results found that 502 did not php-fpm no process, but PHP-FPM zombie.
So there's another option:

Vim restart-php-fpm.sh

#!/bin/bash
my_url=http://www.webyang.net
result= ' curl-i $MY _url  grep http/1.1 '
 
if [N $ Result]; Then
#如果502则会执行这里的内容, casually Add or change
killall-9 php-cgi
service php-fpm Restart
fi
In this case, or manually, if you need to automatically add yourself to the crontab.
chmod 755 restart-php-fpm.sh
Run CRONTAB-E
Set restart-php-fpm.sh to be executed automatically every minute (time can be adjusted on its own request)
*/1 * * * */home/restart-php-fpm.sh
To see if the settings succeeded or failed
Crontab-l

or write a shell dead loop that can be executed in a separate time period.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.