<?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>kill the radio &#187; fastcgi</title>
	<atom:link href="http://blog.killtheradio.net/tag/fastcgi/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.killtheradio.net</link>
	<description>or die trying</description>
	<lastBuildDate>Thu, 15 Dec 2011 20:21:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>NginX as a caching reverse proxy for PHP</title>
		<link>http://blog.killtheradio.net/technology/nginx-as-a-caching-reverse-proxy-for-php/</link>
		<comments>http://blog.killtheradio.net/technology/nginx-as-a-caching-reverse-proxy-for-php/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 08:15:19 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://blog.killtheradio.net/?p=394</guid>
		<description><![CDATA[So I got to thinking. There are some good caching reverse proxies out there, maybe it&#8217;s time to check one out for beeets. Not that we get a ton of traffic or we really need one, but hey what if we get digged or something? Anyway, the setup now is not really what I call [...]]]></description>
			<content:encoded><![CDATA[<p>So I got to thinking. There are some good caching reverse proxies out there, maybe it&#8217;s time to check one out for beeets. Not that we get a ton of traffic or we really need one, but hey what if we get digged or something? Anyway, the setup now is not really what I call simple. <a href="http://haproxy.1wt.eu/" target="_blank">HAproxy</a> sits in front of <a href="http://nginx.org/" target="_blank">NginX</a>, which serves static content and sends PHP requests back to <a href="http://php-fpm.org/" target="_blank">PHP-FPM</a>. That&#8217;s three steps to load a fucking page. Most sites use apache + mod_php (one step)! But I like to tinker, and I like to see requests/second double when I&#8217;m running ab on beeets.</p>
<p>So, I&#8217;d like to try something like <a href="http://varnish-cache.org/" target="_blank">Varnish</a> (sorry, <a href="http://www.squid-cache.org/" target="_blank">Squid</a>) but that&#8217;s adding one more step in between my requests and my content. Sure it would add a great speed boost, but it&#8217;s another layer of complexity. Plus it&#8217;s a whole nother service to ramp up on, which is fun but these days my time is limited. I did some research and found what I was looking for.</p>
<p>NginX has made me cream my pants every time I log onto the server since the day I installed it. It&#8217;s fast, stable, fast, and amazing. Wow, I love it. Now I read that NginX can cache FastCGI requests based on response caching headers. So I set it up, modified the beeets api to send back some <a href="http://www.mnot.net/cache_docs/" target="_blank">Cache-Control</a> junk, and voilà&#8230;a %2800 speed boost on some of the more complicated functions in the API.</p>
<p>Here&#8217;s the config I used:</p>
<pre># in http {}
fastcgi_cache_path /srv/tmp/cache/fastcgi_cache levels=1:2
                           keys_zone=php:16m
                           inactive=5m max_size=500m;</pre>
<pre># after our normal fastcgi_* stuff in server {}
fastcgi_cache php;
fastcgi_cache_key $request_uri$request_body;
fastcgi_cache_valid any 1s;
fastcgi_pass_header Set-Cookie;
fastcgi_buffers 64 4k;</pre>
<p>So we&#8217;re giving it a 500mb cache. It says that any valid cache is saved for 1 second, but this gets overriden with the Cache-Control headers sent by PHP. I&#8217;m using $request_body in the cache key because in our API, the actual request is sent through like:</p>
<pre>GET /events/tags/1 HTTP/1.1
Host: ...

{"page":1,"per_page":10}</pre>
<p>The params are sent through the HTTP body even in a GET. Why? I spent a good amount of time trying to get the API to accept the params through the query string, but decided that adding $request_body to one line in an NginX config was easier that re-working the structure of the API. So far so good.</p>
<p>That&#8217;s FastCGI acting as a reverse proxy cache. Ideally in our setup, HAproxy would be replaced by a reverse proxy cache like Varnish, and NginX would just stupidly forward requests to PHP like it was earlier today&#8230;but I like HAproxy. Having a health-checking load-balancer on every web server affords some interesting failover opportunities.</p>
<p>Anyway, hope this helps someone. NginX <span style="text-decoration: underline;">can</span> be a caching reverse proxy. Maybe not the best, but sometimes, just sometimes,  simple &gt; faster.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/nginx-as-a-caching-reverse-proxy-for-php/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Throw apache to the wind?</title>
		<link>http://blog.killtheradio.net/technology/throw-apache-to-the-wind/</link>
		<comments>http://blog.killtheradio.net/technology/throw-apache-to-the-wind/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 20:24:51 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[hosting]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[modproxy]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://killtheradio.dev/?p=26</guid>
		<description><![CDATA[So after hours of searching and tweaking, I finally got the answer I never wanted: it&#8217;s not possible to have apache serve mod_fastcgi requests through it&#8217;s own reverse proxy (ie load-balance mod_fastcgi). I know this is incorrect. But it had taken me so long and wasted so much time getting to the point where I [...]]]></description>
			<content:encoded><![CDATA[<p>So after hours of searching and tweaking, I finally got the answer I never wanted: it&#8217;s not possible to have apache serve mod_fastcgi requests through it&#8217;s own reverse proxy (ie load-balance mod_fastcgi). I know this is incorrect. But it had taken me so long and wasted so much time getting to the point where I was almost as clueless as when I started, that I took drastic action.</p>
<p>I installed <a href="http://www.lighttpd.net/" target="_blank">lighttpd</a>. I already had the FastCGI setup running, not to mention I got a new Linode for testing remote PHP. The only problem was that I couldn&#8217;t load balance between my slack box (web server) and my new linode (debian app server). BTW I chose <a href="http://www.debian.org/" target="_blank">Debian</a> because the image was smaller and from what I know, it&#8217;s essentially the same as Slack. I really haven&#8217;t had ANY problems moving to it yet, and let&#8217;s face it, Deb is a lot more standard. Installing PHP was a bitch, but that&#8217;s what apt-get is for (no, I compiled PHP&#8230;but I&#8217;ll be damned if I&#8217;m going to hand compile all the stupid dependencies).</p>
<p>Anyway, within 20 minutes, lighttpd had PHP running through FastCGI load balanced between two servers. Needless to say, I fell in love. Not to mention all the information I was inundated with along the way about how small and lean lighttpd is swayed this choice a little.</p>
<p>So as far as I know, <a href="http://www.beeets.com" target="_blank">beeets</a> is running great on both of its &#8220;new&#8221; servers and loving it.</p>
<p>There was a bit of trouble getting used to the new URL rewriting scheme, but generally instead of doing apache&#8217;s</p>
<p>RewriteCond blahblah !-f</p>
<p>You can just do url-rewrite(&#8216;(images|css|js)&#8217; =&gt; &#8216;$0&#8242;)</p>
<p>(this is a horrible oversimplification, but you get the idea)&#8230;you write the URLs you DON&#8217;T want to be rewritten to $0. Works wonders.</p>
<p>All that&#8217;s left is some cache-control headers (I&#8217;m crazy about them, if you can&#8217;t tell yet), and some speed testing. I&#8217;m excited to see if lighttpd is actually faster than apache under ab.</p>
<p>Next up, <a href="http://www.capify.org/" target="_blank">Capistrano</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/throw-apache-to-the-wind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache, PHP, FastCGI &#8211; The two day crucible</title>
		<link>http://blog.killtheradio.net/technology/apache-php-fastcgi-the-two-day-crucible/</link>
		<comments>http://blog.killtheradio.net/technology/apache-php-fastcgi-the-two-day-crucible/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 20:14:19 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[servers]]></category>

		<guid isPermaLink="false">http://killtheradio.dev/?p=19</guid>
		<description><![CDATA[Wow. You&#8217;d think it would be easy. In fact, it should have been. Compile a module, load it from apache. Recompile PHP with &#8211;enable-fastcgi&#8230;oh wait, I already had it in there (always thinking ahead!!). Change some apache settings. Right? Yeah, right. It took two days. I can&#8217;t even really remember why. The biggest problem was [...]]]></description>
			<content:encoded><![CDATA[<p>Wow. You&#8217;d think it would be easy. In fact, it should have been. Compile a module, load it from apache. Recompile PHP with &#8211;enable-fastcgi&#8230;oh wait, I already had it in there (always thinking ahead!!). Change some apache settings.</p>
<p>Right? Yeah, right. It took two days. I can&#8217;t even really remember why. The biggest problem was that running make &amp;&amp; make install in the mod_fastcgi source was NOT yielding a &#8216;mod_fastcgi.so&#8217; as the documentation PROMISED! In fact, it installed mod_fastcgi.la instead, a highly useless file.</p>
<p>So how did the master get out of this bind? Beats me, try asking him. As for me, I had to run &#8216;ld -Bshareable *.o -o mod_fastcgi.so&#8217; which is mentioned in some document from a long time ago in a galaxy far, far away.</p>
<p>Let me interject and say that the information on the <a href="http://www.fastcgi.com" target="_blank">FastCGI website</a> is &#8220;not very well documented.&#8221;</p>
<p>Day 2. I figured, what&#8217;s the point of FastCGI if it&#8217;s not set up to connect to a remote App server? Maybe I don&#8217;t HAVE an external server set up, but we can pretend. Well that&#8217;s another nightmare. There&#8217;s a good <a href="http://www.cyberciti.biz/tips/rhel-fedora-centos-apache2-external-php-spawn.html" target="_blank">external FastCGI</a> guide written about it, and guess what it worked. Not really a nightmare at all, come to think of it. Quite pleasant.</p>
<p>All in all, shouldn&#8217;t have taken 2 days =P (I&#8217;m a tinkerer)&#8230;but fuck it, I have FastCGI now, ready to connect to all those App servers I have churning away in the background (one day).</p>
<p>In all the excitement, I also compiled and installed the <a href="http://httpd.apache.org/docs/2.0/mod/worker.html" target="_blank">apache worker-MPM</a>. A few tests with ab didn&#8217;t really show any noticeable difference. But threads are cool, right?</p>
<p>Next up: figure out how to configure Apache to pass all requests ending in .php (whether the file exists on the web server or not) to our &#8220;app&#8221; server. Is this possible?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/apache-php-fastcgi-the-two-day-crucible/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IIS and PHP</title>
		<link>http://blog.killtheradio.net/technology/iis-and-php/</link>
		<comments>http://blog.killtheradio.net/technology/iis-and-php/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 20:13:59 +0000</pubDate>
		<dc:creator>Andrew Lyon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[fastcgi]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[servers]]></category>

		<guid isPermaLink="false">http://killtheradio.dev/?p=16</guid>
		<description><![CDATA[So tonight I helped a client set up PHP5 on IIS 7 using MSSQL 2005. These things always work great in theory but judging my my use of the word &#8220;theory&#8221; in italics, you can probably guess that things weren&#8217;t so smooth in practice. The client was smart enough to get FastCGI working through IIS&#8230;something [...]]]></description>
			<content:encoded><![CDATA[<p>So tonight I helped a client set up PHP5 on IIS 7 using MSSQL 2005. These things always work great in <em>theory</em> but judging my my use of the word &#8220;theory&#8221; in italics, you can probably guess that things weren&#8217;t so smooth in <em>practice</em>.</p>
<p>The client was smart enough to get FastCGI working through IIS&#8230;something I would have probably rolled over on. From then on, it was an upward battle getting a simple PHP prototype project going.</p>
<p>In the later versions of PHP 5, it would seem that all mssql_* functions have&#8230;been&#8230; removed? There is an ntwdblib.dll that needs to be replaced to play nicely with mssql 2005&#8230;but it doesn&#8217;t exist in the latest releases. How strange. I ended up reverting to 5.2.5, making me a not-so-bleeding-edge pushover :&#8217;(. It&#8217;s cool though.</p>
<p>Then MSSQL doesn&#8217;t accept normal logins, only windows ones, and it&#8217;s bloomin&#8217; impossible finding out how to change that.</p>
<p>One thing Microsoft seems to have actually done right is release a rewrite module (much like mod_rewrite) that you don&#8217;t have to frickin&#8217; pay for, which is nice. On a side note, I really hated Windows Server 2008. It&#8217;s like Vista in every way, except that the design is slightly different, somewhat. Sorry, MS, but get your shit together plz, kkthxbai.</p>
<p>Anyway, we got everything going. What a pain in the ass though!</p>
<p>If you&#8217;re wondering, I&#8217;m more of a Unix guy ;). And yes, I <em>have</em> used a computer before.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.killtheradio.net/technology/iis-and-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

