首先,在入口文件中計算出程序開始執行時間
PHP代碼 list($min, $sec) = explode(' ', microtime()); $starttime = (float)$min + (float)$sec;添加助手,並前端控制器中添加開始時間變量
PHP代碼 Zend_Controller_Action_HelperBroker::addHelper(new My_Controller_Action_Helper_Time()); $frontController = Zend_Controller_Front::getInstance(); $frontController->setParam('starttime', $starttime);添加一個控制器助手,在控制器分發完成後將頁面執行時間值賦於視圖變量runtime
PHP代碼 class My_Controller_Action_Helper_Time extends Zend_Controller_Action_Helper_Abstract { public function postDispatch() { $starttime = $this->getFrontController()->getParam('starttime'); list($min, $sec) = explode(' ', microtime()); $endtime = (float)$min + (float)$sec; $this->getActionController()->vIEw->runtime = $endtime - $starttime; } }然後在視圖腳本中輸出頁面執行時間
PHP代碼 <?= $this->runtime ;?>