Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
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

In reply to Training wheels again by le

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.