<?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; php</title>
	<atom:link href="http://www.anchor.com.au/blog/tag/php/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>Performance tips &#8211; good reading for PHP/mysql devs</title>
		<link>http://www.anchor.com.au/blog/2009/10/performance-tips-good-reading-for-phpmysql-devs/</link>
		<comments>http://www.anchor.com.au/blog/2009/10/performance-tips-good-reading-for-phpmysql-devs/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 13:56:26 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[FTW]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=1032</guid>
		<description><![CDATA[I came across this a little while ago; it&#8217;s a good little presentation with some interesting points I&#8217;d not considered before. http://www.slideshare.net/techdude/how-to-kill-mysql-performance If you&#8217;re an Anchor customer, I should point out that the ARCHIVE storage engine isn&#8217;t available in Redhat&#8217;s version of MySQL, which is a damned nuisance.]]></description>
			<content:encoded><![CDATA[<p>I came across this a little while ago; it&#8217;s a good little presentation with some interesting points I&#8217;d not considered before.</p>
<p><a href="http://www.slideshare.net/techdude/how-to-kill-mysql-performance">http://www.slideshare.net/techdude/how-to-kill-mysql-performance</a></p>
<p>If you&#8217;re an Anchor customer, I should point out that the ARCHIVE storage engine isn&#8217;t available in Redhat&#8217;s version of MySQL, which is a damned nuisance. <img src='http://www.anchor.com.au/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/10/performance-tips-good-reading-for-phpmysql-devs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>goto considered harmful &#8211; oh, wait, it&#8217;s just PHP</title>
		<link>http://www.anchor.com.au/blog/2009/07/goto-considered-harmful-oh-wait-its-just-php/</link>
		<comments>http://www.anchor.com.au/blog/2009/07/goto-considered-harmful-oh-wait-its-just-php/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 02:20:36 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[WTF]]></category>
		<category><![CDATA[considered harmful]]></category>
		<category><![CDATA[goto]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xkcd]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=1017</guid>
		<description><![CDATA[Hot on the heels of PHP 5.3&#8242;s snazzy new namespaces, here comes goto. I kid you not, see for yourself: http://au2.php.net/goto Even Java, which we have little fondness for here, does not give you goto. This has to be one of the worst misfeatures yet in 5.3 (as opposed to the native MySQL driver, which [...]]]></description>
			<content:encoded><![CDATA[<p>Hot on the heels of PHP 5.3&#8242;s snazzy new <a href="http://au2.php.net/manual/en/language.namespaces.rationale.php">namespaces</a>, here comes goto. I kid you not, see for yourself:</p>
<p><a href="http://au2.php.net/goto">http://au2.php.net/goto</a></p>
<p>Even Java, which we have little fondness for here, does not give you goto. This has to be one of the worst misfeatures yet in 5.3 (as opposed to the native MySQL driver, which only causes customers to ask for stupid things, like installing pre-alpha code on their production webserver).</p>
<p>In case it weren&#8217;t clear enough, they go so far as to use <a href="http://xkcd.com/292/">an XKCD strip</a> that highlights how bad an idea this is. I suspect this is some kind of sick joke&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/07/goto-considered-harmful-oh-wait-its-just-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developers, you can stop your crap authentication schemes now. Please.</title>
		<link>http://www.anchor.com.au/blog/2009/05/developers-you-can-stop-your-crap-authentication-schemes-now-please/</link>
		<comments>http://www.anchor.com.au/blog/2009/05/developers-you-can-stop-your-crap-authentication-schemes-now-please/#comments</comments>
		<pubDate>Fri, 22 May 2009 00:05:39 +0000</pubDate>
		<dc:creator>Barney Desmond</dc:creator>
				<category><![CDATA[FTW]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.anchor.com.au/blog/?p=925</guid>
		<description><![CDATA[I really like cryptography and security. I was lucky enough to take it as a subject at UNSW before I graduated. I found this earlier this evening; it&#8217;s a little old (~18 months), but that doesn&#8217;t make it any less relevant, so it&#8217;s a good read. There&#8217;s the odd inaccuracy here and there, but it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I really like cryptography and security. I was lucky enough to <a href="http://www.cse.unsw.edu.au/~cs3441/">take it as a subject at UNSW</a> before I graduated.</p>
<p>I found this earlier this evening; it&#8217;s a little old (~18 months), but that doesn&#8217;t make it any less relevant, so it&#8217;s a good read. There&#8217;s the odd inaccuracy here and there, but it&#8217;s solid stuff, and relevant to anyone writing webapp code to handle authentication.<br />
<a href="http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/"> http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/</a></p>
<p>The article focuses heavily on one particular authentication methodology, because it&#8217;s something a lot of people do. After you read it, you&#8217;ll understand that it&#8217;s something a lot of people do <em>poorly</em>. It assumes a reasonable degree of knowledge about what you&#8217;re doing (ay, there&#8217;s the rub), but the best lesson to be learnt there is that <em><strong>you</strong> shouldn&#8217;t be writing that code!</em> Just stop! Someone&#8217;s already done it better than you, and it&#8217;s been checked by a lot more people than you and your colleague, who reckons it &#8220;looks pretty secure&#8221;. If you&#8217;ve got time to read all the comments on the article you&#8217;ll find a rollercoaster of people saying, &#8220;wouldn&#8217;t it be secure if I just..?&#8221; Just don&#8217;t do it. <span style="text-decoration: line-through;">Don&#8217;t write my security code, bro!</span></p>
<p>Just using a proper authentication mechanism means you can spend your valuable time on more important things.</p>
<ul>
<li>Like not building SQL queries in a piecemeal manner, using unsanitised user-supplied data</li>
<li>Like not making your whole site world-writeable so you can handle file uploads (you don&#8217;t have to do this on <strong>our</strong> <a href="http://www.anchor.com.au/web-hosting/website-hosting.py">shared hosting</a> servers)</li>
<li>Like fixing your newsletter signup process so it requires <a href="http://www.anchor.com.au/hosting/support/BulkEmailMarketing/BeforeYouStart">double opt-in</a>, saving you from filling your database with spurious accounts and causing massive headaches when you do a campaign mailout</li>
<li>Like <a href="http://www.anchor.com.au/hosting/dedicated/SQL_Query_Optimisation">optimising your database schema for bitchin&#8217; performance</a> &#8211; do you retain a DBA on a six-figure salary to do this for you? Nah I didn&#8217;t think so, this is cheaper and much more fun</li>
<li>Like checking that your code doesn&#8217;t spew 14 PHP Warns/Errors to the apache logs for every page access, and fill the partition</li>
<li>Like trying to get nice round corners on your page elements <img src='http://www.anchor.com.au/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.anchor.com.au/blog/2009/05/developers-you-can-stop-your-crap-authentication-schemes-now-please/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>

