首页 > 后端开发 > 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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板