<?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>Anchor Web Hosting Blog &#187; apache</title>
	<atom:link href="http://www.anchor.com.au/blog/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anchor.com.au/blog</link>
	<description>A view into the Anchor Engineroom</description>
	<lastBuildDate>Wed, 08 Feb 2012 00:51:36 +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 on shared hosting &#8211; doing it better</title>
		<link>http://www.anchor.com.au/blog/2010/09/php-on-shared-hosting-doing-it-better/</link>
		<comments>http://www.anchor.com.au/blog/2010/09/php-on-shared-hosting-doing-it-better/#comments</comments>
		<pubDate>Sat, 11 Sep 2010 00:47:48 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[FTW]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[mod_php]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[shared hosting]]></category>
		<category><![CDATA[suexec]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=1497</guid>
		<description><![CDATA[Large scale shared hosting with an out-of-the-box install of apache and PHP is a recipe for security-disaster; this is not news. The solution is to run each website&#8217;s code separately so they can&#8217;t affect each other. This is pretty common nowadays but it wasn&#8217;t always the case with many providers. Anchor&#8217;s been doing this for [...]]]></description>
			<content:encoded><![CDATA[<p>Large scale shared hosting with an out-of-the-box install of apache and PHP is a recipe for security-disaster; this is not news. The solution is to run each website&#8217;s code separately so they can&#8217;t affect each other. This is pretty common nowadays but it wasn&#8217;t always the case with many providers.</p>
<p>Anchor&#8217;s been doing this for what must be about ten years now. That&#8217;s way longer than I&#8217;ve been employed here, but what with our tech-director-and-co-founder being busy stuntjumping his scooter over rows of parked cars, it&#8217;s fallen to me to write this one up.</p>
<p><a href="http://www.anchor.com.au/hosting/support/How-Anchor-runs-PHP-as-CGI-on-shared-hosting">We use apache&#8217;s mod_suexec to run PHP scripts as though they&#8217;re CGI scripts</a>, and it works great. There&#8217;s lots of guides out there about how to do this for yourself, but for us one of the most important things when deploying a solution is to ensure that it <em>Just Works</em>, for everyone. When we do it right, nothing breaks and noone notices a thing, because it works exactly as everyone expects. That&#8217;s what we&#8217;ve done.</p>
<p>It&#8217;s also one of the reasons that apache isn&#8217;t going anywhere in a hurry. Newer tech like nginx is an absolute performance-demon compared to apache, but the barrier to entry is way too high if your goal is &#8220;throw the site on the server and make it work&#8221;. Everyone writes apps assuming they&#8217;ll be deployed to apache. As a hosting company, if you&#8217;re not offering something compatible you&#8217;d better have a good ace up your sleeve.</p>
<p>So, we give you a rundown on <a href="http://www.anchor.com.au/hosting/support/How-Anchor-runs-PHP-as-CGI-on-shared-hosting">how Anchor does PHP; it&#8217;s secure and it just works</a>. There are many others like it, but this one is ours. If you&#8217;re an existing customer, we hope you&#8217;ve never had to think about it. If you&#8217;ve got any questions we&#8217;d love to hear them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2010/09/php-on-shared-hosting-doing-it-better/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting failure modes, episode 2501</title>
		<link>http://www.anchor.com.au/blog/2009/10/interesting-failure-modes-episode-2501/</link>
		<comments>http://www.anchor.com.au/blog/2009/10/interesting-failure-modes-episode-2501/#comments</comments>
		<pubDate>Mon, 05 Oct 2009 10:08:25 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[WTF]]></category>
		<category><![CDATA[alert]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[diskspace]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sms]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=1254</guid>
		<description><![CDATA[I got woken up by a SMS for low diskspace the other night on one of our customer&#8217;s servers. Okay, so that&#8217;s a lie, I never sleep, but the SMS is real. Oh great, they&#8217;re making whoopie on their mailing lists again and making some stupidly huge logfile. Little did I know just how huge [...]]]></description>
			<content:encoded><![CDATA[<p>I got woken up by a SMS for low diskspace the other night on one of our customer&#8217;s servers. Okay, so that&#8217;s a lie, I never sleep, but the SMS is real.</p>
<blockquote><p>Oh great, they&#8217;re making whoopie on their mailing lists again and making some stupidly huge logfile.</p></blockquote>
<p>Little did I know just how huge that file was. How about 735gb huge, in the space of 12hrs? This customer is already a bit of an oddball, what with 1.4TiB of usable space in their server. &#8220;Oh that&#8217;s nothing&#8221;, you say. Sure, I&#8217;ve got a few TiB of kitten pictures on my machine at home, just like you, but to put things in perspective: 300GiB of space would be &#8220;big&#8221; for most Anchor customers. SCSI disks cost about $1.70/Gb, compared to about 10c/Gb for SATA.</p>
<p>There was no mailout. No big processing job, and no flood of activity. With a little digging I was able to nail it down to an apache errorlog file. That was a surprise, except for the PHP errors all throughout &#8211; some things never change.</p>
<pre>[Fri Oct 02 02:39:57 2009] [error] [client 63.82.71.139] PHP Warning: fgets(): supplied
argument is not a valid stream resource in /home/wright/public_html/script.php on
line 15, referer: XXX</pre>
<p>Nice work there, guys. You need to learn to check your return values from failure-prone functions.</p>
<p>Strangely, there were no actual active connections, but the process list showed two apache processes going balls to the wall, writing the same error message to the log file ad infinitum. By my reckoning that was over 9000 lines per second &#8211; nothing a quick service-restart couldn&#8217;t fix, thankfully.</p>
<p>And to actually fix the problem? It&#8217;s tempting to dump the file, but we don&#8217;t like doing that; it&#8217;s just a bit <em>too</em> cowboy for us. I settled for a forced logrotate run, taking about 4hrs and squishing it down to just 4.3GiB &#8211; Crisis (and sleep) Averted.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/10/interesting-failure-modes-episode-2501/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Old-skool webserver</title>
		<link>http://www.anchor.com.au/blog/2009/05/old-skool-webserver/</link>
		<comments>http://www.anchor.com.au/blog/2009/05/old-skool-webserver/#comments</comments>
		<pubDate>Fri, 22 May 2009 00:07:38 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[WTF]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=936</guid>
		<description><![CDATA[Not quite as zippy as most of the stuff we deploy, but no less admirable for it. http://www.humanclock.com/webserver.php I&#8217;m currently porting apache 1.3.14 to the venerable TI-89, it should be finished in about 5-6 weeks.]]></description>
			<content:encoded><![CDATA[<p>Not quite as zippy as most of the stuff we deploy, but no less admirable for it.<br />
<a href="http://www.humanclock.com/webserver.php"> http://www.humanclock.com/webserver.php</a></p>
<p>I&#8217;m currently porting apache 1.3.14 to the venerable <a href="http://en.wikipedia.org/wiki/TI-89">TI-89</a>, it should be finished in about 5-6 weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/05/old-skool-webserver/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The importance of keeping clean log files</title>
		<link>http://www.anchor.com.au/blog/2009/05/the-importance-of-keeping-clean-log-files/</link>
		<comments>http://www.anchor.com.au/blog/2009/05/the-importance-of-keeping-clean-log-files/#comments</comments>
		<pubDate>Thu, 21 May 2009 03:15:42 +0000</pubDate>
		<dc:creator>oliver</dc:creator>
				<category><![CDATA[FTW]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[error_log]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[robots]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=919</guid>
		<description><![CDATA[I was shoulder-surfing a colleague today while they were trying to diagnose a webserver problem for a client. I noticed, certainly not for the first time, that the Apache error log message was filled with messages like &#8220;robots.txt not found&#8221; and &#8220;favicon.ico not found&#8221;. Surely these must be amongst the most frequently logged errors (if [...]]]></description>
			<content:encoded><![CDATA[<p>I was shoulder-surfing a colleague today while they were trying to diagnose a webserver problem for a client. I noticed, certainly not for the first time, that the Apache error log message was filled with messages like &#8220;robots.txt not found&#8221; and &#8220;favicon.ico not found&#8221;. Surely these must be amongst the most frequently logged errors (if not the top two).</p>
<p>Multiplied by many hundreds of servers, with millions of hits per day, and you have a significant amount of disk space being taken up by these trivial messages. What&#8217;s more, any time you spend scrolling through the hordes of messages like these is time taken away from debugging the real problem, if it exists.</p>
<p>So please, be kind to your sysadmin and include a robots.txt and favicon.ico for your website. It makes sense from a search engine point of view and makes your website just a little bit prettier, so why not?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/05/the-importance-of-keeping-clean-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Winning the war on PHP memory leakage</title>
		<link>http://www.anchor.com.au/blog/2008/11/winning-the-war-on-php-memory-leakage/</link>
		<comments>http://www.anchor.com.au/blog/2008/11/winning-the-war-on-php-memory-leakage/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 01:17:53 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[FTW]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[leak]]></category>
		<category><![CDATA[logrotate]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[swap]]></category>
		<category><![CDATA[trending]]></category>
		<category><![CDATA[zpush]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=61</guid>
		<description><![CDATA[One of our dedicated server customers recently had a problem with the machine keeling over and dying for a few days in a row, for no apparent reason. This necessitated a remote reboot of the server to get it running again (we cut the power to both power supplies for a few seconds). The immediate [...]]]></description>
			<content:encoded><![CDATA[<p>One of our dedicated server customers recently had a problem with the machine keeling over and dying for a few days in a row, for no apparent reason. This necessitated a remote reboot of the server to get it running again (we cut the power to both power supplies for a few seconds). The immediate suspicion was faulty hardware, but this should rarely be the case as we put our hardware through a thorough &#8220;burn in&#8221; period before it&#8217;s ever deployed. In addition to this, it was happening pretty regularly in the middle of the day.</p>
<p>After spotting this pattern, a quick look at our trending graphs showed us the problem very clearly. The machine was steadily using all available physical memory. Once this ran out, the system starts pushing data off to swapspace, which is on the disks. Once this runs out the OS simply has no more memory to give. It&#8217;ll start <a title="Wikipedia article on Out Of Memory condition, &quot;oom killer&quot;" href="http://en.wikipedia.org/wiki/Out_of_memory">killing off processes in a desperate attempt to reclaim some memory</a>, but this is rarely successful.</p>
<p><span id="more-61"></span></p>
<p>Curiously, on days that the server didn&#8217;t die we saw a chunk of memory being released early in the morning. This pointed to a maintenance cronjob doing something, but what?</p>
<p><a href="http://www.anchor.com.au/blog/wp-content/uploads/2008/11/mirai_memoryusage.png"><img class="size-medium wp-image-83 alignnone" src="http://www.anchor.com.au/blog/wp-content/uploads/2008/11/mirai_memoryusage-300x128.png" alt="mirai's memory usage" width="300" height="128" /></a></p>
<p>This should more accurately be described as a graph of non-critical memory allocation; buffers and caches can be quickly discarded to free up memory for applications that really need it. Note the sawtooth wave pattern with a period of 1 day.</p>
<p><a href="http://www.anchor.com.au/blog/wp-content/uploads/2008/11/mirai_swapspace.png"><img class="size-medium wp-image-84 alignnone" src="http://www.anchor.com.au/blog/wp-content/uploads/2008/11/mirai_swapspace-300x121.png" alt="mirai's swapspace usage" width="300" height="121" /></a></p>
<p>Swapspace usage can be seen peaking multiple times over the course of a few days, corresponding to times when the server resembled a glorious fireball</p>
<p>We were now well-prepared to catch the system in the act. We kept an eye on trending graphs and waited for the memory usage get out of hand. When we logged in, what we saw was surprising. Apache was consuming vast amounts of memory, highly irregular for a server which has the primary function of a mail server. Having a look at apache&#8217;s logs, we noticed a lot of failed requests to Zpush, an open-source implementation of the MS Exchange protocol for syncing data to mobile clients (iPhones, in this case), written in PHP.</p>
<blockquote>
<pre>PHP Fatal error:  Allowed memory size of 16777216 bytes exhausted (tried
to allocate 727553 bytes) in /home/zpush/zpush/include/mimeDecode.php
on line 292</pre>
</blockquote>
<p>PHP is usually a pretty sturdy beast. It sanitises the environment between requests, effectively <a title="Wikipedia article on sandboxing for isolation" href="http://en.wikipedia.org/wiki/Sandbox_(computer_security)">sandboxing</a> different users&#8217; code from each other. It&#8217;s certainly possible to write pathologically broken code, but generally this shouldn&#8217;t affect anyone badly except for yourself.</p>
<p>For whatever reason, zpush was exceeding its local memory limits in the backend MIME parser and dying. This is a condition that PHP should recover from gracefully, but that clearly wasn&#8217;t happening. With zpush being regularly called by the customer&#8217;s iPhones, this was leaking a little bit of memory every single time. Because apache wasn&#8217;t dying outright, the memory never got freed.</p>
<p>A whole lot of things suddenly made sense. Apache will eventually recycle its processes (after 4,000 requests), but on a lightly-used server like this one, apache was only dealing with zpush requests. Spread over 8 child processes, apache could in theory take some 32,000 hits before it gets close to saving itself. This also had a clean explanation for the early morning respite: logrotate will <a title="USR1 signals a graceful restart of apache" href="http://httpd.apache.org/docs/2.2/stopping.html">signal apache to do a graceful restart</a> after processing the logs for the day, which will restart the child processes, freeing the memory.</p>
<p>In this instance, the most straighforward solution was to disable zpush. If this weren&#8217;t an option then further investigation would be needed. Increasing the PHP memory limit beyond 16MB in php.ini woud do the job, but we&#8217;d really like to know <em>why</em> it&#8217;s trying to allocate so much memory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2008/11/winning-the-war-on-php-memory-leakage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

