by June 1, 2009 0 comments

Over the last couple of months we have checked how well PHP integrates with
IIS and lets you run multiple open source and other PHP web apps easily and
efficiently. This time we tried benchmarking PHP with both IIS 7 and Apache to
see how well it performs. The whole process wasn’t a mere cake walk, for, while
hunting for some PHP based benchmarks for web servers we did land into multiple
projects. To our dismay, none of them worked with both platforms without
modifying the code little bit. As we were trying to check the performance for
both architectures (Windows and Linux) in identical conditions, it was not
possible for us to run optimized scripts on them to get the result. So we
decided to write our own code.

The Code
The requirement here was to create a very simple script in PHP which could
run on any OS and web server without any optimization, and was able to take some
time to run so that we could measure it. To do so, we decided to write a code
which would calculate the value of pi a given number of times and will throw
back the number of seconds it took to do so. The code was something like this.

Direct Hit!

Applies To: Web Admins, PHP Developers
USP: Understand how well PHP works on different platforms
Primary Link:
PHP, IIS, Apache

$start = time();
$num_pi = 2000;
function sqr($num) { return $num*$num; }
function calcdis($x, $y) {
$calcdis = sqrt(sqr($x-1)+sqr($y-1));
return $calcdis;
function getpie($num = 0, $InCircle = 0, $x = 0, $y = 0 , $calcd = 0) {
global $num_pi;
$InCircle = 0;
for($i = 1; $i <= $num_pi; $i++) {
$x = rand(1,200)/100;
$y = rand(1,200)/100;
$calcd = calcdis($x,$y);
$InCircle = $InCircle + 1;
$getpie = ($InCircle*4)/$num_pi;
return $getpie;
$pie = getpie();
echo ‘One appox. value of pi: ‘, $pie;
for($i = 1; $i <= $num_pi; $i++) {
$pie = getpie();


$took = time()-$start;
echo ‘<br />It took ‘, $took, ‘ seconds to calculate pi ‘, $num_pi, ‘ times,
which is ‘, $num_pi/$took, ‘ calculations a second’;

While installing PHP for Windows, you can select the Windows
based web server you want to integrate PHP with.
You can see Linux is winning throughout, but the performance
difference is decreasing as you increase the load.

Once this was ready and tested to be running, we created four instances of
this code with different values for “$num_pi”. With this variable we would
define the number of times the program would try to calculate pi, so all four
instances contained the same code with $num_pi = 500/1000/2000/ 4000. This means
we were going to test the web servers by judging the time taken for calculating
the value of pi 500 to 4000 times. The output of the script was something like

One appox. value of pi: 3.104
It took 1 seconds to calculate pi 500 times, which is 500 calculations a

The setup
Once the benchmark was ready and kicking, the second step was to create an
identical machine. So, instead of building an identical machine for both the
Oses, we decided to go for a dual boot machine. This made sure that the machine
wasn’t just identical but actually the same in both cases so that there was no
chance of getting any performance difference due to hardware issues. The machine
which we used was a Core2 Duo machine with 2 GB RAM.

Once the machine was up and running, we installed Fedora 10 64-bit and
Windows Server 2008 Datacenter Edition. The Linux machine had Apache 2.2 and PHP
5.2 installed on it. And on the Windows machine we installed IIS 7 with FastCGI
enabled and then installed PHP 5.2.9 (latest release as of today) on the same

The OSes and the web servers were kept in their default stage and no
optimization was done so that we could compare the raw performance of the
servers with default settings.

The result
The result we have got till now shows that clearly Linux is the winner in
the race. If you see the graph you will notice that when the script was executed
on both OSes with a number of calculation = 500, Apache machine finished the
task in half the time of the IIS machine. But as we increased the number of
calculations, the gap between both servers kept reducing gradually. This can
even mean that IIS is out of the box tuned for huge web servers with more load,
whereas Apache is tuned for workstation class web servers. It can even mean that
Apache and Linux work best with PHP.

Due to time constraint, we were not able to run more tests and so provide a
final conclusion. We will continue this test from 4000+ number of calculations
and try to see whether the performance graph increases or otherwise. Watch out
for the next part of this story.

For any comments or suggestions please catch us at

No Comments so far

Jump into a conversation

No Comments Yet!

You can be the one to start a conversation.

Your data will be safe!Your e-mail address will not be published. Also other data will not be shared with third person.