<?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>MrBrown blob &#187; php</title>
	<atom:link href="http://charles.lescampeurs.org/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://charles.lescampeurs.org</link>
	<description>random bits.</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:34:09 +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>Memory usage by group of processes</title>
		<link>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=memory-usage-by-group-of-processes</link>
		<comments>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes#comments</comments>
		<pubDate>Fri, 13 Mar 2009 14:14:26 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Command line]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=173</guid>
		<description><![CDATA[While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage. Playing with memory_limit in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk. First, get the number of php running processes: # ps aux &#124; grep php-cgi &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage.</p>
<p>Playing with <em>memory_limit</em> in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk.</p>
<p>First, get the number of php running processes:</p>
<pre># ps aux | grep php-cgi | grep -v grep | wc -l
126</pre>
<p>Then, use awk to calculate the average memory usage for these processes:</p>
<pre># ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'
33987.8</pre>
<p>The number used in the calculation is the field RSS given by ps. The ps manual page says:</p>
<blockquote><p>rss: resident set size, the non-swapped physical memory that a task has used (in kiloBytes)</p></blockquote>
<p>You can also calculate the total memory used by all php-cgi processes:</p>
<pre># ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s;}'
4302028</pre>
<p>If you need to watch the trend of this average memory usage, a little shell loop does the trick:</p>
<pre># while [ 1 ]; do ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'; sleep 2; done
34401.3
34405.1
34408.4
34409.4
34414.2
34417</pre>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=173" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintenance mode (HTTP 503) with lighttpd and PHP</title>
		<link>http://charles.lescampeurs.org/2008/07/22/maintenance-mode-http-503-with-lighttpd-and-php?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=maintenance-mode-http-503-with-lighttpd-and-php</link>
		<comments>http://charles.lescampeurs.org/2008/07/22/maintenance-mode-http-503-with-lighttpd-and-php#comments</comments>
		<pubDate>Tue, 22 Jul 2008 00:28:08 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[http]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=28</guid>
		<description><![CDATA[When you put your website in maintenance mode, it&#8217;s a good idea to return a HTTP 503 error code to the client. This code indicates that &#8220;the server is currently unable to handle the request due to a temporary overloading or maintenance of the server&#8221;. The 503 code is used to avoid crawlers or caching [...]]]></description>
			<content:encoded><![CDATA[<p>When you put your website in maintenance mode, it&#8217;s a good idea to return a HTTP 503 error code to the client.</p>
<p>This code indicates that <em>&#8220;the server is currently unable to handle the request due to a    temporary overloading or maintenance of the server&#8221;</em>.</p>
<p>The 503 code is used to avoid crawlers or caching proxy use the maintenance page as the new valid content for the request. You certainly don&#8217;t want Google save this content in his search index as the content of your website <img src='http://charles.lescampeurs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>To achieve this we will use a rewrite rule in lighttpd to redirect all requests to a single PHP script which will return a 503 error code and print an informative message.</p>
<h2>Lighttpd configuration</h2>
<pre>url.rewrite = ( "" =&gt; "/maintenance.php" )</pre>
<p>This configuration will redirect any request to maintenance.php script.</p>
<p>If you need to serve an image in your maintenance page, you have to add another rule to the rewrite process like that :</p>
<pre>url.rewrite = ( "upgrading.png" =&gt; "$0",
                "" =&gt; "/maintenance.php" )</pre>
<h3>Let some users see the website</h3>
<p>It might be usefull to let admins or developers access the website during the maintenance.<br />
For that, you can disable the maintenance rewrite rule for certain IP addresses :</p>
<pre> $HTTP["remoteip"] != “192.168.1.42″ {
               url.rewrite = ( "upgrading.png" =&gt; "$0",
                      "" =&gt; "/maintenance.php" )
}</pre>
<h2>PHP code example</h2>
<pre>&lt;?php
header("HTTP/1.1 503 Service Unavailable");
?&gt;
We're currently upgrading our servers...</pre>
<h2>Links</h2>
<ul>
<li><a title="HTTP/1.1 error codes" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html" target="_blank">RFC 2616 HTTP/1.1</a></li>
<li><a title="HTTP status codes" href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes">HTTP status codes on Wikipedia</a></li>
</ul>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=28" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2008/07/22/maintenance-mode-http-503-with-lighttpd-and-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

