I want to calculate the execution time of popen function in PHP. The function is not provide execution time as default.
My pseudo code like below;
$handle = popen($cmd, 'r');
while (!feof($handle)) {
$buffer = fgets($handle, FREAD_BUFFER_SIZE);
$out .= $buffer . " ";
}
I found a solution in here but I am not sure it's the right way.
Consider using the time() or microtime(true) function.
$currentTimeinSeconds = microtime(true);
This stores the seconds passed from the instance it was declared to 1/01/1970. Make two variables (ex. T1 and T2) and simply subtract the second to the first to get the execution time.
$t1= microtime(true)
[function]
$t2= microtime(true)
ex_time=$t2-$t1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.