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 CGI.pm 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
(using CGI.pm)
29
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 CGI.pm 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
(using CGI.pm)
29
PHP script 53
Apache::Registry script,
without CGI.pm
60!

Wow, this is a big performance gain, isn't it? Almost the same script, but without CGI.pm. 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

FreeBSD 4.1-STABLE
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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.