Re: measuring script execution time

From: Date: Thu, 08 Nov 2007 14:47:28 +0000
Subject: Re: measuring script execution time
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-264227@lists.php.net to get a copy of this message
On 11/8/07, pobox@verysmall.org <pobox@verysmall.org> wrote: > Hello, > > running php 5.x as Apache module (both 1.3.x and 2.2.x) seems to report > longer execution time when users sit on slower connection. Is it > possible that end of script execution is when the last bit is passed to > the user by Apache and the connection is closed? > > Any workaround around that? > > Thanks, > Iv > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > By name alone (a recursive acronym), PHP stands for PHP Hypertext Preprocessor. That means, before the HTML or other output is sent to Apache to be served to the client, PHP has parsed, interpreted, processed, and returned all of the code, and then terminated the PHP process. As to why code execution appears to take longer on slower connections, my guess would be that it's a matter of coincidence. You could try doing something like this, if you don't already have something similar in place: <? // Add to the VERY top of the file being executed, before includes, et cetera. function microtime_float() { // Don't put in include file; that file will have to parse list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $_SCRIPT['exec_sess'] = time(); $_SCRIPT['client_ip'] = $_SERVER['REMOTE_ADDR']; $_SCRIPT['time_start'] = microtime_float(); // Continue with your code.... /* YOUR CODE HERE */ // Now, at the very bottom of the script.... $_SCRIPT['time_stop'] = microtime_float(); $_SCRIPT['time_total'] = round(($_SCRIPT['time_stop'] - $_SCRIPT['time_start']),4); $write_contents = <<<EOL == SESSION $_SCRIPT['exec_sess'] for $_SCRIPT['client_ip'] == Start recording: $_SCRIPT['time_start']; Stop recording: $_SCRIPT['time_stop']; Total execution time: $_SCRIPT['time_total']; EOL; file_put_contents('./php_exec_time_log',$write_contents,FILE_APPEND); ?> -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you.

« previous php.general (#264227) next »