首頁 > 後端開發 > php教程 > php-fpm经常出现502解决办法

php-fpm经常出现502解决办法

WBOY
發布: 2016-06-13 12:13:34
原創
1216 人瀏覽過

php-fpm经常出现502解决方法

更多请支持:http://www.webyang.net/Html/web/article_134.html


最近nginx经常502,解决502最好的办法就是重启php-fpm。
手动去重启还是比较麻烦的事情,最好的就是扔到shell里去。

vim restart-php-fpm.sh

<span class="com">#!/bin/sh</span><span class="pln">SERVICE</span><span class="pun">=</span><span class="pln">\'php</span><span class="pun">-</span><span class="pln">fpm\'</span><span class="com">#if ps ax | grep -v grep | grep $SERVICE > /dev/null</span><span class="pln"></span><span class="kwd">if</span><span class="pln"> netstat </span><span class="pun">-</span><span class="pln">anp </span><span class="pun">|</span><span class="pln"> grep </span><span class="lit">9000</span><span class="pln"> </span><span class="pun">></span><span class="pln"> </span><span class="str">/dev/</span><span class="kwd">null</span><span class="pln"></span><span class="kwd">then</span><span class="pln">    echo \"$SERVICE service running</span><span class="pun">,</span><span class="pln"> everything </span><span class="kwd">is</span><span class="pln"> fine\"</span><span class="kwd">else</span><span class="pln">    echo \"$SERVICE </span><span class="kwd">is</span><span class="pln"> </span><span class="kwd">not</span><span class="pln"> running\"    service php</span><span class="pun">-</span><span class="pln">fpm start</span><span class="kwd">fi</span>
登入後複製
本地虚拟机测试了一下,可行,扔到服务器上去,结果发现502的时候并未php-fpm没有进程,而是php-fpm僵死。
所以走了另外一种方案:

vim restart-php-fpm.sh

<span class="com">#!/bin/bash</span><span class="pln">MY_URL</span><span class="pun">=</span><span class="pln">\"http</span><span class="pun">:</span><span class="com">//www.webyang.net\"</span><span class="pln">RESULT</span><span class="pun">=</span><span class="pln">\'curl </span><span class="pun">-</span><span class="pln">I $MY_URL </span><span class="pun">|</span><span class="pln"> grep \"HTTP</span><span class="pun">/</span><span class="lit">1.1</span><span class="pln"> </span><span class="lit">502</span><span class="pln">\"\' </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">[</span><span class="pln"> </span><span class="pun">-</span><span class="pln">n \"$RESULT\" </span><span class="pun">];</span><span class="pln"> </span><span class="kwd">then</span><span class="pln"></span><span class="com">#如果502则会执行这里的内容,随便加或改</span><span class="pln">killall </span><span class="pun">-</span><span class="lit">9</span><span class="pln"> php</span><span class="pun">-</span><span class="pln">cgiservice php</span><span class="pun">-</span><span class="pln">fpm restart</span><span class="kwd">fi</span>
登入後複製
这样的话,还是手动的,如果需要自动,自己添加到crontab里去。
chmod 755 restart-php-fpm.sh
运行crontab -e
设置restart-php-fpm.sh 每一分钟自动执行一次(时间可以按自己要求调)
*/1 * * * * /home/restart-php-fpm.sh
查看设置成功还是失败
crontab -l

或者写一个shell死循环,隔一个时间段去执行即可。


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板