note 77810 deleted from function.register-shutdown-function by cmb
| From: | cmb@php.net | Date: | Sun, 03 Feb 2019 18:06:06 +0000 |
| Subject: | note 77810 deleted from function.register-shutdown-function by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210183@lists.php.net to get a copy of this message | ||
Note Submitter: dcez at land dot ru
----
This simple function (i gues) is for measuring page generation time in microseconds, using earlier
mentioned register_shutdown_function...
Here is an example:
<?php
set_time_limit(0);
function check_time($time_str, $end = false){
global $start; //Need some global variable where we will ceep our start time
list($msec, $sec) = explode(' ', $time_str);
$result = bcadd($msec, $sec, 10);
if(!$end){
$start = $result;
register_shutdown_function('check_time', microtime(), 'true');
//Function registrates itself only with some parametrs now
}elseif($end){
$end = $result;
echo '<br />Page was generated in '.bcsub($end, $start, 10).'
seconds...<br />';
}
}
check_time(microtime()); //Caling our function once!
//Doing some job which we will measure...
$fd = fopen('users.txt', 'r');
while(!feof($fd)){
$buffer .= fread($fd, 1024);
}
fclose($fd);
?>
As you see may be its large, but you dont have to call "check_time" function twice, in the
start and at the end of the script, as many users usually do...