Jump to content

How long does my page take to complete?


cliftonbazaar

Recommended Posts

I have the following code on a page

<?PHP session_start();?>
<HTML>

<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<TITLE>Running Test Cricket</TITLE>
</HEAD>

<BODY>
<?PHP
echo "Time at start ".$_SERVER['REQUEST_TIME'];
#This is our hourly updates for teams if it is due - it is set off by the variable 'teamUpdateTime'
echo "<BR>1";
$updateTime=time();  #Get the current time and put it into the variable
$teams = mysql_query("SELECT * FROM teams WHERE teamUpdateTime<'$updateTime'");  //Go through all the teams
while($team = mysql_fetch_array($teams)) {
	echo "<BR>UPDATING - hourly - ".$team['name']; #Show the team we are updating
	include("../updates/hourly_update_team.php");  #Update all the teams that are due to be updated
}
echo "<BR>2";

  	mysql_close($sqldb);  //Close the database

echo "<BR>Time at end ".$_SERVER['REQUEST_TIME'];
?>
</BODY></HTML>

While the code is crude it is not for the public to see - it is for updating teams in an online game I am creating.

What my problem is that the REQUEST_TIME at the start and end of the code are always outputted the same; the code is there to see how long the page takes to do.  I sit there and count how long the page takes to activate (load, whatever the terminology is) and it can take up to 40 seconds - but the REQUEST_TIME tells me it takes 0 seconds so obviously something is wrong.

 

My question is simple - how do I get this code to output the REQUEST_TIME when the code starts and when it finished, thus showing me how long it took for the page to load.  I wish to do this to try and speed it up.

 

James

Link to comment
https://forums.phpfreaks.com/topic/233238-how-long-does-my-page-take-to-complete/
Share on other sites

Try putting this at the top:

$starttime = $_SERVER['REQUEST_TIME'];

and this at the end of when you want to stop counting:

$endtime = time();

Then, when you want to output the number of seconds it took, just do

echo "Page took ".($endtime-$starttime)."s to generate.";

Or something like that. If you want more precise timing, use microtime instead:

$starttime = microtime(true);
$endtime = microtime(true);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.