Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.