Web Hosting Talk







View Full Version : PHP Load time too big


Oakii
04-17-2005, 07:24 PM
I'm using this script



<?php

// Insert this block of code at the very top of your page:

$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$start = $time;

// Place this part at the very end of your page

$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$finish = $time;
$totaltime = ($finish - $start);
printf ("This page took %f seconds to load.", $totaltime);

?>

From http://www.totallyphp.co.uk/code/page_load_time.htm

on www.AndrewKao.com

The index file of this site calls each respective section of the site. I put $time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$start = $time; at the very top. Because my footer has a design, rather then putting the rest of the script at the very bottom of the index file, I put it in the respective place in the footer (near bottom.. good enough).

The script runs, however I'm getting messages like

This page took 1113780068.989929 seconds to load


*scroll down to very bottom of page*

That is obviously incorrect. What would cause such a error?

Thanks

Marble
04-18-2005, 03:25 AM
Its this line that is giving you the wrong decimal point:
$time = $time[1] + $time[0];

I have something similar I use:

function start_load_timer ()
{
$timeparts = explode(' ',microtime());
return $timeparts[1].substr($timeparts[0],1);
}

function end_load_timer ($starttime)
{
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
return bcsub($endtime,$starttime,6);
}

$start = start_load_timer ();

// end:
echo end_load_timer ($start);

/* note I am using bc math module, but its just substraction. */

Oakii
04-18-2005, 03:41 AM
Getting 1113809946.936401

Not much better.

Would I have to have all the above in the same file? or can I go something like

index.php

<?php
function start_load_timer ()
{
$timeparts = explode(' ',microtime());
return $timeparts[1].substr($timeparts[0],1);
}

function end_load_timer ($starttime)
{
$timeparts = explode(' ',microtime());
$endtime = $timeparts[1].substr($timeparts[0],1);
return bcsub($endtime,$starttime,6);
}

$start = start_load_timer ();
include('main.php');
include('footer.php');
?>


footer.php

<?
<!--stuff-->
echo end_load_timer ($start);
echo "seconds";
</designs>
</body></html>
?>


Thanks much