我正在使用Yii开发一个时间表系统,所有工作都很好,但我如何能得到一个脚本或动作的执行时间。
例如,我有一个动作 "scheduleOptimize",我想知道在PHP中运行这个动作需要多长时间。
谁能帮助我,请。
Thanx in advance
是的,你可以用 Logging
选项
请参考这个链接。
http:/www.yiiframework.comdocguide1.1entopics.logging
你可以做。
简单的片段,以秒为单位返回执行时间,5个符号后的逗号精度。
<?php echo sprintf('%0.5f',Yii::getLogger()->getExecutionTime())?>
你不需要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;
如果有人想知道Yii2开始后的执行时间,我建议如下。
\Yii::getLogger()->getElapsedTime();
你可以用它来计算你喜欢的次数。它使用一个在框架开始时定义的常量作为 "开始时间",并从current_timestamp()中减去它。