The first question a developer facing a performance issue should check is if they're using the right programming language. Perhaps the language interpreter causes most of the slow down, so there's little point in optimizing the code; it'll never be enough.
Several programming languages were benchmarked to check how fast they were compared to PHP. The benchmarks involved a lot of different types of scripts using different operations; the results are an average of all the tests.
CGI Perl scripts
The traditional way to code web sites and applications just one or two years ago
FastCGI Perl scripts
A mechanism to improve the performance problems of CGI scripts
Python CGI scripts
In this case we used Python to code CGI scripts
mod_python Python scripts
An Apache module to let Apache run Python code without calling the Python interpreter
C CGI scripts
Compiled C scripts running as CGI programs
mod_perl Perl scripts
An Apache module to let Apache run Perl scripts without having to execute the Perl interpreter
PHP
To compare the other languages to PHP, the same test were run on PHP
After several benchmarks, including different script types and server loads, it was found that mod_perl, FastCGi, and PHP were the fastest options with very similar results. Therefore, if a PHP site or script is facing a performance problem then the solution is to work with the code and not change the language.
Test 1 – 1000 executions of a very short script:
Language |
Time (seconds) |
---|---|
C |
20.6 |
Perl |
23.8 |
Python |
45.2 |
PHP |
16.0 |
mod_python |
30.0 |
mod_perl |
16.4 |
FastCGI |
16.4 |
Test 2 – 1000 executions of a long script, more than 1000 lines of code:
Language |
Time (seconds) |
---|---|
C |
258 |
Perl |
963 |
Python |
978 |
PHP |
304 |
mod_python |
347 |
mod_perl |
476 |
FastCGI |
280 |