Re: [PHP] Logging PHP Execution time to a file?

This is a discussion on Re: [PHP] Logging PHP Execution time to a file? within the PHP General forums, part of the PHP Programming Forums category; I use this function: function echo_pt($add='') { static $pt = 0; if($pt==0) { $pt = miro_time(); return; } $time_start = explode(' ', $pt); $time_end = ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-14-2003
Marek Kilimajer
 
Posts: n/a
Default Re: [PHP] Logging PHP Execution time to a file?

I use this function:
function echo_pt($add='') {
static $pt = 0;
if($pt==0) {
$pt = miro_time();
return;
}
$time_start = explode(' ', $pt);
$time_end = explode(' ', microtime());
$parse_time = number_format(($time_end[1] + $time_end[0] -
($time_start[1] + $time_start[0])), 3);
echo '<!-- Parse Time '.$add.': ' . $parse_time . 's -->';
$pt=microtime();
}

Usage:
it needs to be initialized first:
echo_pt();
then simply call as many times as you need:
echo_pt('some string');
and it will show you seconds elapsed from the last call to this
function, so you can easily see where the script spends most of its
time. Instead of echoing it you can append it to a file.

Lasse Laursen wrote:

> Hi all,
>
> We are "debugging" some web applications to try to determine where the
> problems with long execution time is.
>
> Is it possible to log the execution time of each script executed to a
> logfile? The PHP processes are run as FastCGI under Zeus.
>
> Regards
> --
> Lasse Laursen · VP, Hosting Technology · NetGroup A/S
> St. Kongensgade 40H · DK-1264 Copenhagen K, Denmark
> Phone: +45 3370 1526 · Fax: +45 3313 0066
>
> - Don't be fooled by cheap finnish imitations - BSD is the One True Code
>
>
>


Reply With Quote
  #2 (permalink)  
Old 07-14-2003
Jeff Harris
 
Posts: n/a
Default Re: [PHP] Logging PHP Execution time to a file?

On Jul 14, 2003, "Marek Kilimajer" claimed that:

|I use this function:
|function echo_pt($add='') {
| static $pt = 0;
| if($pt==0) {
| $pt = miro_time();
| return;
| }
| $time_start = explode(' ', $pt);
| $time_end = explode(' ', microtime());
| $parse_time = number_format(($time_end[1] + $time_end[0] -
| ($time_start[1] + $time_start[0])), 3);
| echo '<!-- Parse Time '.$add.': ' . $parse_time . 's -->';
| $pt=microtime();
|}
|
|Usage:
|it needs to be initialized first:
|echo_pt();
|then simply call as many times as you need:
|echo_pt('some string');
|and it will show you seconds elapsed from the last call to this
|function, so you can easily see where the script spends most of its
|time. Instead of echoing it you can append it to a file.
|
|Lasse Laursen wrote:
|
|> Hi all,
|>
|> We are "debugging" some web applications to try to determine where the
|> problems with long execution time is.
|>
|> Is it possible to log the execution time of each script executed to a
|> logfile? The PHP processes are run as FastCGI under Zeus.
|>
|> Regards
|> --
|> Lasse Laursen · VP, Hosting Technology · NetGroup A/S
|> St. Kongensgade 40H · DK-1264 Copenhagen K, Denmark
|> Phone: +45 3370 1526 · Fax: +45 3313 0066
|>
|> - Don't be fooled by cheap finnish imitations - BSD is the One True Code
|>
--

It seems to me that many people (usually CMS systems or shopping carts)
try to re-invent the wheel. The pear repository is filled with many
packages, hopefully more to come, and the Benchmark Package is one of
them.

require_once "Benchmark/Timer.php";
$timer = new Benchmark_Timer;
$timer -> start();
// Plenty of code...
$timer -> stop();
print("<!-- Total execution time: ");
print($timer-> timeElapsed());
print(" seconds. -->\n");

Jeff
--
Registered Linux user #304026.
"lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import"
Key fingerprint = 52FC 20BD 025A 8C13 5FC6 68C6 9CF9 46C2 B089 0FED
Responses to this message should conform to RFC 1855.


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:09 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0