I guess everyone here knows what merlyn thinks about PHP: "Training wheels without the bike". This is easy to say for someone like him, but in fact PHP is really popular, and there must be a reason for this.

Today I took some benchmarks to see how PHP compares against mod_perl, and the results are quite interesting. (I probably wouldn't have posted them here, but some folks on the chatterbox demanded them.)

I have two scripts, that do the same thing: they connect to a MySQL address database and show a list of entries. They produce the same output. One is written in PHP, the other one is written in Perl, using and running as an Apache::Registry script under mod_perl.

The benchmarking tool I used is "ab", the Apache Benchmark that comes with the Apache distribution. I didn't tune the server at all, leaving default entries for configuration details like MinSpareServers (5), MaxSpareServers (10), StartServers (5), MaxClients (150), MaxRequestsPerChild (0).

I simulated 10 users, where each user will make 10 requests, so we have a total of 100 requests. Each script was tested several runs, and these are the average numbers of requests per second that Apache could handle:

  Requests per second
Perl script under Apache::Registry
PHP script 53!

This was quite a shock to me. It means that the PHP script is almost twice as fast than the Perl script! Where has the famous performance of mod_perl gone?

I didn't want to believe this, so I hacked a third script, all in all a copy of the Perl script, only different in that I didn't use this time, but vanilla Apache methods for parameter handling, headers setup and so on. The results look like this:

  Requests per second
Perl script under Apache::Registry
PHP script 53
Apache::Registry script,

Wow, this is a big performance gain, isn't it? Almost the same script, but without I'm curious if it can get faster when I make it a real content handler instead of an Apache::Registry script, but I didn't have the time for that.

Used hard- and software:
AMD K6 400MHz,
128 MB RAM

Apache 1.3.12
mod_perl 1.24
mod_php 4.0.2
DBI 1.14
Mysql-Modules 1.2214