Consider the following PHP program:
<?echo date("c"); `date` echo date("c");?>
The backtick-operator `` simply executes the specified command via the shell.
Output on my local windows-box using
time instead of
2012-02-27T10:21:37+01:00 Current time: 10:21:37[...] 2012-02-27T10:21:37+01:00
As expected, printing the time like this took about 0 seconds.
Output on the production server (Mac OS X) however is
2012-02-27T10:26:29+01:00 Mon Feb 27 10:26:47 CET 2012 2012-02-27T10:26:47+01:00
and when reloading the page:
2012-02-27T10:24:40+01:00 Mon Feb 27 10:24:40 CET 2012 2012-02-27T10:24:40+01:00
So the first time the system tries a system call like this for a new connection it takes 18 seconds and the second and further times 0 seconds.
Here is (almost) the same without running through Apache:
$ time php -r 'echo date("c");echo `date`;echo date("c");' 2012-02-28T10:49:23+01:00 Tue Feb 28 10:49:23 CET 2012 2012-02-28T10:49:23+01:00 real 0m0.890s user 0m0.011s sys 0m0.879s $
Without Apache it takes less than a second even on the first attempt.
I think it is either Apache or some interaction between Apache and PHP.
What settings may cause this and how do I fix or debug it?