Here is a function I sometimes use to log that will show you the time
that has passed since the last log entry. I find it very useful, so that
you can test a section of code's execution time simply by surrounding it
with calls to this function.
Maybe it will be useful to you.
Chris
function log_message($log_file, $log_message)
{
global $last_log_write;
# SET FORMATTED DATE
$formatted_date=date("Y-m-d H:i:s");
# IF THIS IS THE FIRST LOG MESSAGE
if (!isset($last_log_write))
{
error_log("[$formatted_date] [-----------------]
$log_message\n", "3", $log_file);
$last_log_write=microtime();
$last_log_write=explode(" ", $last_log_write);
$last_log_write=doubleval($last_log_write["1"]) +
doubleval($last_log_write["0"]);
}
# ELSE (THIS IS NOT THE FIRST MESSAGE), CALCULATE TIME SINCE LAST LOG
else
{
$curr_log_write=microtime();
$curr_log_write=explode(" ", $curr_log_write);
$curr_log_write=doubleval($curr_log_write["1"]) +
doubleval($curr_log_write["0"]);
$elapsed_time=$curr_log_write-$last_log_write;
$elapsed_time=substr($elapsed_time, "0", "8");
$log_message=str_replace("\r", "", $log_message);
$log_message=str_replace("\n",
"\n ", $log_message);
error_log("[$formatted_date] [+$elapsed_time seconds]
$log_message\n", "3", $log_file);
$last_log_write=$curr_log_write;
}
}
?>
-=[ Julien Bonastre ]=- wrote:
>The idea is a page "execution" timer.. or a database query timer.. basically it shows
>you just a time (usually in msecs) it took for the last command to be executed.. I
>have seen it used for queries and it returns the time it took.. And I am quite sure
>I've seen it used for actual page generation as well, whereby it says something like
>"page generated in x.xxx secs"
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php