Chào bác
> tôi thấy nhiều diễn đàn có cái thông báo: trang này được xử
> lý trong xxx giây. Có ai biết giải thuật để làm việc đó như
> thế nào không?
Cái này em đã từng xem trong manual của PHP, một ví dụ về microtime()
usage: string microtime ( )
available since: PHP 3, PHP 4
Function này sẽ trả lại string dạng "msec sec".
- sec is the current time measured in the number of seconds since the Unix Epoch (0:00:00 January 1, 1970 GMT)
- msec is the microseconds part.
This function is only available on operating systems that support the gettimeofday() system call.
Both portions of the string are returned in units of seconds.
Đây là đọan code ví dụ em lấy trong PHP Manual, có thêm mấy cái echo để biết chính xác cái gì xảy ra
<?php
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
echo "Start at ".$time_start."<br>";
for ($i=0; $i < 10; $i++){
//do nothing, 10 times
echo ("usec sec: ".microtime()."<br>");
}
$time_end = getmicrotime();
echo "End at ".$time_end."<br>";
$time = $time_end - $time_start;
echo "Did nothing in $time seconds";
?>