Heim > Backend-Entwicklung > PHP-Tutorial > php-fpm经常出现502解决办法

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

WBOY
Freigeben: 2016-06-13 12:13:34
Original
1221 Leute haben es durchsucht

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>
Nach dem Login kopieren
本地虚拟机测试了一下,可行,扔到服务器上去,结果发现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>
Nach dem Login kopieren
这样的话,还是手动的,如果需要自动,自己添加到crontab里去。
chmod 755 restart-php-fpm.sh
运行crontab -e
设置restart-php-fpm.sh 每一分钟自动执行一次(时间可以按自己要求调)
*/1 * * * * /home/restart-php-fpm.sh
查看设置成功还是失败
crontab -l

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


Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage