2014-01-13 52 views
3

我正在开发一个使用Yii的时间表系统。 所有工作正常,但我怎样才能得到一个脚本或行动的时间执行。如何在Yii中记录脚本的执行时间?

例如,我有“scheduleOptimize”操作。 我想知道在PHP中运行该操作需要多长时间。

有人帮助我。

Thanx in advance

回答

9

简单的片段,以秒为单位返回执行时间,逗号精度后的5个符号。

<?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime())?> 
1

你不需要Yii为你做。使用原生PHP。

$start_time = microtime(true); 

//Do you stuff here 
do_stuff('here'); 

$end_time = microtime(true); 

//dividing with 60 will give the execution time in minutes other wise seconds 
$execution_time = ($end_time - $start_time)/60; 
+0

为什么downvote(没有解释)。这是100%的工作,并建议,而不是增加另一个多层次调用到库,将提供倾斜的结果。如果你打扰检查。 Yii在CLogger {}类中使用microtime()。 – crafter

+0

这是一个很好的答案....不知道谁投下了它......我自己使用这个......伟大的答案的人。 – kebyang

相关问题