香港专业教育学院在这里搜索和谷歌,但无法找到任何类似的东西,有没有办法看到某个进程需要多长时间在PHP?
我正在运行zend_lucene并希望输出搜索结果显示给用户所需的时间.
我建议这个:
microtime() 以微秒返回当前的Unix时间戳
所以你可以在执行搜索之前获得microtime,然后在操作结束时重新获取它.然后你可以简单地减去end_timewith start_time,你得到你的搜索多长时间.
// get the time in microseconds before your search
$start_time = microtime(true);
/**
* your code here
*
*/
// get the time in microseconds when you search is done
$end_time = microtime(true);
// finally subtract and print the time elapsed
echo $start_time - $end_time;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助 :-)