I'm trying to to calculate the load time of one php page (say aaa.php) using another php page (say bbb.php). Anybody can give me a tip on how to do this?
[solved] measure load time of a webpage
Moderator: General Moderators
[solved] measure load time of a webpage
Newbie here
,
I'm trying to to calculate the load time of one php page (say aaa.php) using another php page (say bbb.php). Anybody can give me a tip on how to do this?
I'm trying to to calculate the load time of one php page (say aaa.php) using another php page (say bbb.php). Anybody can give me a tip on how to do this?
Last edited by damithc on Thu Sep 22, 2005 6:31 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
thx for the reply coderGoblin,
microtime() does solve my problem, but only partly.
here's the (pseudo)code for what i intend to do.
$starttime=microtime();
load external page
$endtime=microtime();
$loadtime=$starttime-$endtime;
it's the load external page part that i don't know how to do. any suggestions?
microtime() does solve my problem, but only partly.
here's the (pseudo)code for what i intend to do.
$starttime=microtime();
load external page
$endtime=microtime();
$loadtime=$starttime-$endtime;
it's the load external page part that i don't know how to do. any suggestions?
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
To include the other page use the include() function.
If using php4 you need the function given in the example (full code below).
If using php4 you need the function given in the example (full code below).
Code: Select all
<?php
/**
* Simple function to replicate PHP 5 behaviour
*/
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
// Process Subpage
include ("bbb.php");
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "bbb.php processed in $time seconds\n";
?>almost there. thx a lot CoderGoblin for your continuous help. 
in my case, i don't want to include contents of bbb.php in my aaa.php. Rather, aaa.php should only display the load time of bbb.php.
i tried it anyway, and hit upon another probem. When i include aaa.php inside bbb.php, aaa.php complains that HTTP_USER_AGENT is not defined.

in my case, i don't want to include contents of bbb.php in my aaa.php. Rather, aaa.php should only display the load time of bbb.php.
i tried it anyway, and hit upon another probem. When i include aaa.php inside bbb.php, aaa.php complains that HTTP_USER_AGENT is not defined.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Not sure about the error (would potentially need to look at your code) but In this case I would be tempted to use a session variable. (OK I know whole different subject)
bbb.php
aaa.php
Or something similar (PHP4 needs that microtime function (possibly in an include). Hope that helps. (Note I have placed the values in the arrays so aaa.php show all runs of anytimed files, not just one.)
bbb.php
Code: Select all
<?php
session_start();
$time_start = microtime();
//Do all your processing;
$time_end = microtime();
$time = $time_end - $time_start;
if (isset($_SESSION['timings']['bbb'])) {
$_SESSION['timings']['bbb'][]="processed in $time seconds\n";
} else {
$_SESSION['timings']['bbb'][0]="processed in $time seconds\n";
}
?>Code: Select all
<?php
session_start();
if (isset($_SESSION['timings']) {
foreach ($_SESSION['timings'] as $page=>$values) {
foreach ($values as $index=>$timestr) {
echo("Page $page Run ".($index+1)." $timestr<br />");
}
echo('<hr />');
}
} else {
echo("No timing details");
}
?>Or something similar (PHP4 needs that microtime function (possibly in an include). Hope that helps. (Note I have placed the values in the arrays so aaa.php show all runs of anytimed files, not just one.)
Last edited by CoderGoblin on Thu Sep 22, 2005 6:50 am, edited 2 times in total.
that did the trick! thx a million. you made my day 
fixed two minor errors:
should be session_start(); in both cases
should be if (isset($_SESSION['timings']['bbb'])) {
fixed two minor errors:
Code: Select all
sesion_start();Code: Select all
if (isset($_SESSION['bbb'])) {...- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany