PDA

View Full Version : Mini hack request - page creation time


Martz
11-07-2001, 12:41 PM
How hard would it be to have how long it took mySQL and/or php to do their work for each page displayed?

Like if I was to do index.php?showqueries=1 I'd get:


Page generated in 3.1261730194092 seconds with 30 queries,
spending 2.8116569519043 doing MySQL queries and 0.31451606750488 doing PHP things.

at the bottom of the page. Just a thought, its somewhich I'd like to include on my page - would anyone else? :)

Reeve of shinra
11-07-2001, 12:43 PM
Perhaps you already can do this, but it would be interesting to track the averages per forum from the admin panel for optimization purposes.

Martz
11-07-2001, 12:48 PM
I had a quick look in my global.php (not admin) and there was a few references to the showqueries thing - nothing easily obvious for me to spot and hack though :/

dirgotronix
11-07-2001, 12:52 PM
On my actual site, I have something like this in effect.

I used the following code to achieve this effect:

(from my index, the title is the following)
return $dirgotronix.net[content/News]; // 1.724 sec.

Here's the code:

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

// At the top of the page you're counting, put the following:
$begin_time = getmicrotime();

// And at the bottom, this:
$end_time = getmicrotime();
$load_time = $end_time - $begin_time;
echo number_format($load_time,3);

You might be able the hack it a bit to accomidate the forum. That only echos the number of seconds to 3 decimal places, but that's all I needed on my site. Hope it's of some use!

Scott MacVicar
11-07-2001, 03:02 PM
its already added in to show queries instead of content just add &explain=1 to any vbulletin page, i think it should be able to be modified though to show content and queries instead of just the query info.

Martz
01-14-2002, 04:13 PM
Thought I would bump this - I've chewed it over and not worked out how to do it. I still think it would be a great hack. However I don't especially need it, but I'm sometimes unsure if the forums are slow, or my connection is c**p. Its also nice to show off a quick server. :)

Any thoughts? :)

Admin
01-16-2002, 02:25 PM
In global.php (forum folder) replace:
if (isset($showqueries)) {
$pagestarttime=microtime();
}
with:
// if (isset($showqueries)) {
$pagestarttime=microtime();
// }
And now in functions.php (admin folder) replace:
if ($showqueries) {
$pageendtime=microtime();

$starttime=explode(" ",$pagestarttime);
$endtime=explode(" ",$pageendtime);

$totaltime=$endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];

$vartext.="<!-- Page generated in $totaltime seconds with $query_count queries -->";
}
with:
// if ($showqueries) {
$pageendtime=microtime();

$starttime=explode(" ",$pagestarttime);
$endtime=explode(" ",$pageendtime);

$totaltime=$endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];

$vartext.="<!-- Page generated in $totaltime seconds with $query_count queries -->";
// }
That will give you the info you want at the bottom of every HTML source code, in a <!-- comment --> (see this page's source code for example).

Adding it in the footer would require some more hacking (because the footer template is eval()'ed right when the script stats executing, so it doesn't have this info when it is eval()'ed).

Martz
01-16-2002, 08:45 PM
Damn thats great :)

Thanks for looking into that one, even if it isn't displayed on the page its a good thing to have imo. Good work!

Many thanks.