Lazyweb Request: Why would PHP be *faster* than HTML?

With the help of the great guys at Slicehost.com, I am attempting to run my benchmark series on a virtual private server, to compare with EC2. However, I’m seeing a very strange result for the baselines: a PHP page delivers more requests-per-second than a static HTML page.

The OS is a stock Ubuntu 8.10 installation; you can see the setup steps here.

The virtual private server has 2 gigs of RAM, and is on a box by itself, so there is no other external activity to skew the results.

I ran ab -c 10 -t 60 http://localhost/ on each of two files: index.html, which has only the static text “hello world”; and index.php, which has only the code <?php echo 'hello world'; ?>.

Here are the results without APC, averaged over 5 one-minute runs:


index.html : 7067.57 req/sec
index.php  : 7484.57 req/sec # faster???

Here are the results with APC, averaged over 5 one-minute runs:


index.html : 7013.50 req/sec
index.php  : 8041.06 req/sec # faster???

I haven’t seen this behavior on EC2. I’m not complaining, but it does seem unintuitive; invoking the PHP interpreter should be more expensive than just delivering a static HTML file. Does anyone have ideas as to why this might be happening?

UPDATE: With the help of Paul Reinheimer, we appear to have found the culprit: the ab tool itself seems to be at fault. Running similar tests by hand with siege returns much more reasonable and expected numbers (~4000 req/sec for HTML, ~3200 for PHP). I’m going to re-work the test scripts to use siege later and report back. Thanks to everyone who provided suggestions, and special thanks to Paul Reinheimer for working through it with me today.

Say “No” To Smarty!

I just discovered nosmarty.net in my Solar referrer logs. I have little love for Smarty, so it’s nice to see this:

First released in January 2001, Smarty has become a stagnant, bug-ridden mess—and also the most popular PHP templating engine in use today. But it shouldn’t be. No Smarty was created to warn developers about its use and encourage the use of superior alternatives.

Hey guys, you might want to add Savant to your list of PHP5 alternatives. Aside from that, great site!

UPDATE: To those who think my tone is inappropriate — “I’m not disrespectful, I’m just ahead of the curve.” </joker> 😉

UPDATE (Thu 05 Jan): Please note that I am not affiliated with nosmarty.net in any way. I just saw it in my referrer logs and linked to it in this post. Thank, Ivo Jansch, for pointing out the need for clarity here.

UPDATE (Thu 05 Jan 10:56): A commenter below opines “If Smarty is used in the right manner, I don’t see why it can’t have it’s place within the arsenal of tools for developers to use.” I respond that there *is* no right manner in which to use Smarty; it’s solving the wrong problem. I expound on that here:

You may have heard that you need to keep your PHP and HTML separated, but that’s not quite the case. Instead, what you need is to keep your “business logic” separate from your “presentation logic”, and that’s a different thing entirely.

Thus, all that’s required is a way to keep your views and controllers separated, and perhaps provide helpers for common view tasks. Then you can use plain PHP in your view scripts (templates), without needing a whole new language.