<?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>Gokhan Geyik - Gokko &#187; PHP</title>
	<atom:link href="http://blog.gokko.net/category/coding/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gokko.net</link>
	<description>Kucuk Daglari Ben Kodladim!</description>
	<lastBuildDate>Wed, 21 Dec 2011 13:31:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP ile Apache Kurtarmaca</title>
		<link>http://blog.gokko.net/2011/12/19/php-ile-apache-kurtarmaca/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-ile-apache-kurtarmaca</link>
		<comments>http://blog.gokko.net/2011/12/19/php-ile-apache-kurtarmaca/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 19:20:35 +0000</pubDate>
		<dc:creator>gokko</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Socket]]></category>

		<guid isPermaLink="false">http://blog.gokko.net/?p=22</guid>
		<description><![CDATA[Bazen ağır yük altında çalışan servislerin saçma sapan sekteye uğradığına tanık oluyorum. Eğer kökten çözum o an için külfetli bir hal aldıysa minik scriptler ile günü kurtarmayı tercih ediyorum. Aslında bu geçici çözümü, TCP çalışan herhangi bir servise uygulayabilirsiniz. Ben TCP Port 80 için olanını paylaşıyorum, siz ihtiyacınız dogrultusunda değişiklik yaparsınız elbet. Script PHP ile [...]]]></description>
			<content:encoded><![CDATA[<p>Bazen ağır yük altında çalışan servislerin saçma sapan sekteye uğradığına tanık oluyorum. Eğer kökten çözum o an için külfetli bir hal aldıysa minik scriptler ile günü kurtarmayı tercih ediyorum. Aslında bu geçici çözümü, TCP çalışan herhangi bir servise uygulayabilirsiniz. Ben TCP Port 80 için olanını paylaşıyorum, siz ihtiyacınız dogrultusunda değişiklik yaparsınız elbet.</p>
<p>Script PHP ile socket baglantisi aciyor ve ön tanimli süre(5 saniye) boyunca servisten cevap alamazsa servisi yeniden başlatıyor. Script FreeBSD, OpenSUSE Server ve Ubuntu Server üzerinde çalıştı ve beni baş ağrısından bir süreliğine kurtardı.</p>
<p>Shebang pathini ve servisin rc scriptini sisteminize göre düzenlemek durumunda olduğunuzu hatırlatmama gerek var mi? Aşağıdaki kod Ubuntu Server pathine göre ayarlandı.<br />
<span id="more-22"></span><br />
Mubabbetle kullanınız.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #990000;">set_time_limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$pf</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/tmp/httpFixxer.pid&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$address</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'IP BURAYA GELECEK'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$port</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pf</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
 <span style="color: #990000;">touch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$socket</span><span style="color: #339933;">=</span><span style="color: #990000;">socket_create</span><span style="color: #009900;">&#40;</span>AF_INET<span style="color: #339933;">,</span> SOCK_STREAM<span style="color: #339933;">,</span> SOL_TCP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #339933;">@</span><span style="color: #990000;">socket_set_option</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> SOL_SOCKET<span style="color: #339933;">,</span> SO_SNDTIMEO<span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sec'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'usec'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!@</span><span style="color: #990000;">socket_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #339933;">,</span> <span style="color: #000088;">$address</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</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: #0000ff;">&quot;/etc/init.d/apache2 restart&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">socket_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$socket</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #339933;">@</span><span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #339933;">@</span><span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pf</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.gokko.net/2011/12/19/php-ile-apache-kurtarmaca/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

