Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to get time (ms) from php request to response for each hit on a page.

Can this be done through lighttpd, or should it be done in php? How?

If done in php, what would be the best performing way of keeping the data so that storing the data does not cost 1/2 of the duration!?

share|improve this question

Place this code in first line after open tag PHP:

$time = explode(' ', microtime());
$time = $time[1] + $time[0];
$begintime = $time;

And place this code before closing tag PHP:

$time = explode(" ", microtime());
$time = $time[1] + $time[0];
$endtime = $time;
$totaltime = ($endtime - $begintime);
echo $totaltime.' seconds';

You can store the result in Mysql with 'INSERT DELAYED' for maximum performance.

share|improve this answer
I like it. Never knew about the "DELAYED" option! That'll actually save a lot of time in the page that I was wanting to time!! I'll mark it true in another hour. Just want to see if there are any other ideas floating out there. – divitiae Oct 28 '11 at 21:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.