Prior to the release of PHP 4, Perl mongers were more than happy to offer head-to-head tests between a PHP script and a similar Perl script, because they were safe in the knowledge that Perl outperformed PHP pretty much hands-down. However, since PHP 4, and particularly since PHP 5.1, PHP has really made big progress in terms of raw speed.

The change between v3 and v4 was largest, though - to give you an idea of the speed improvement, I wrote a simple test script that works in both PHP 3 and PHP 4. It simply creates an array of 1000 different random numbers, then sorts the array. When executing this script 1000 times, PHP 3 managed to achieve 19.51 requests per second on a 500MHz Linux box, compared to PHP 4's 43.08 requests per second - quite a difference, and the program was only four lines long!

So, PHP 4 performance was certainly nothing to be sniffed at. You will see a much bigger performance difference when using a more complicated script, and even higher numbers if you use the opcode cache that's built in as of PHP 5.5.

Later on in the book I will be discussing how to maximise your script performance by squeezing out every drop of performance available.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Competing Languages >>

Previous chapter: Output Control

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.