代码拉取完成,页面将自动刷新
<?php
/**
* Created by PhpStorm.
* User: 80053521
* Date: 2015/4/20
* Time: 17:22
*/
namespace fbi\xhprof;
use fbi\xhprof\controllers\DefaultController;
use fbi\xhprof\lib\Helper;
use fbi\xhprof\lib\XHProfRuns_Default;
use logger\Logger;
use yii\base\Application;
use yii\base\BootstrapInterface;
class Module extends \yii\base\Module implements BootstrapInterface{
/**
* @var int 多少次请求记录一次
*/
public $frequency=1000;
/**
* @var int 执行时间超过多少才记录
*/
public $minExcutionTime=2;
/**
* @var null 记录名称
*/
public $name=null;
/**
* if user hasn't set a directory location,
* we use the xhprof.output_dir ini setting
* if specified, else we default to the directory
* in which the error_log file resides.
* @var null
*/
public $dir='@runtime/xhprof';
public function init(){
parent::init();
if($this->dir) {
$this->dir = \Yii::getAlias($this->dir);
}elseif($dir=ini_set('xhprof.output_dir')){
$this->dir=$dir;
}else{
$this->dir=\Yii::getAlias('@runtime/xhprof');
}
!is_dir($this->dir) and mkdir($this->dir, 0777, true);
}
public function bootstrap($app){
$this->name=is_null($this->name)?\Yii::$app->id:$this->name;
$this->name=preg_replace("/[^\w\.\-]/",'',$this->name);
if(mt_rand(1,$this->frequency)==1){
$app->on(Application::EVENT_BEFORE_REQUEST, function () {
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
register_shutdown_function([$this,'record']);
});
}
}
public function record(){
$xhprof_data = xhprof_disable();
if(microtime(true)-YII_BEGIN_TIME>$this->minExcutionTime
&& ! \Yii::$app->requestedAction->controller instanceof DefaultController
) {
$xhprof_runs = new XHProfRuns_Default($this->dir);
$xhprof_runs->save_run($xhprof_data, $this->name);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。