<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>深度VPS &#187; 自动重启</title>
	<atom:link href="http://www.deepvps.com/tag/%E8%87%AA%E5%8A%A8%E9%87%8D%E5%90%AF/feed" rel="self" type="application/rss+xml" />
	<link>http://www.deepvps.com</link>
	<description>专注VPS技术，关注前端技术</description>
	<lastBuildDate>Sat, 04 Feb 2023 14:00:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Nginx 遇到 502 Bad Gateway 自动重启脚本</title>
		<link>http://www.deepvps.com/nginx-502-bad-gateway-automatically-restart-script.html</link>
		<comments>http://www.deepvps.com/nginx-502-bad-gateway-automatically-restart-script.html#comments</comments>
		<pubDate>Mon, 31 May 2010 05:25:18 +0000</pubDate>
		<dc:creator>deepvps</dc:creator>
				<category><![CDATA[VPS管理维护]]></category>
		<category><![CDATA[502]]></category>
		<category><![CDATA[Bad Gateway]]></category>
		<category><![CDATA[Crontab]]></category>
		<category><![CDATA[php-fpm]]></category>
		<category><![CDATA[脚本]]></category>
		<category><![CDATA[自动重启]]></category>

		<guid isPermaLink="false">http://www.deepvps.com/?p=447</guid>
		<description><![CDATA[放到crontab里一分钟执行一次。url和cmd根据自己的改。
原理就是用curl获取HTTP头，发现502状态码就执行重启php-fpm的命令。

#!/usr/bin/php
&#60;!--$url = 'http://www.deepvps.com';
$cmd = '/usr/local/php/sbin/php-fpm restart';
&#160;
for&#40;$i = 0; $i &#60; 5; $i ++&#41;&#123;         $exec = &#34;curl  connect-timeout 3 -I $url 2&#62;/dev/null&#34;;
        $res = shell_exec&#40;$exec&#41;;
&#160;
        if&#40;stripos&#40;$res, '502 Bad Gateway'&#41; !== false&#41;&#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p>放到crontab里一分钟执行一次。url和cmd根据自己的改。<br />
原理就是用curl获取HTTP头，发现502状态码就执行重启php-fpm的命令。</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/php
</span><span style="color: #339933;">&lt;!--</span><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.deepvps.com'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cmd</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'/usr/local/php/sbin/php-fpm restart'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>         <span style="color: #000088;">$exec</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;curl  connect-timeout 3 -I <span style="color: #006699; font-weight: bold;">$url</span> 2&gt;/dev/null&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$res</span> <span style="color: #339933;">=</span> <span style="color: #990000;">shell_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$exec</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">stripos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$res</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'502 Bad Gateway'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #990000;">shell_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">--&gt;</span></pre></div></div>

<p><span id="more-447"></span>至于crontab，请自行Google搜索</p>
<p>转自：http://www.hostloc.com/viewthread.php?tid=19208&amp;page=1#pid235729</p>
]]></content:encoded>
			<wfw:commentRss>http://www.deepvps.com/nginx-502-bad-gateway-automatically-restart-script.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
