CI框架

安装Xhprof参考:http://www.cnblogs.com/qq917937712/p/8889001.html

第一步:配置config.php

$config['enable_hooks'] = TRUE;

第二步:配置钩子

ci钩子使用手册:http://codeigniter.org.cn/user_guide/general/hooks.html

$hook['pre_controller'] = array(
    'class'    => 'Xhprof',
    'function' => 'start',
    'filename' => 'Xhprof.php',
    'filepath' => 'hooks',
    'params'   => array()
);


$hook['display_override'] = array(
    'class'    => 'Xhprof',
    'function' => 'end',
    'filename' => 'Xhprof.php',
    'filepath' => 'hooks',
    'params'   => array()
);

第三步:钩子具体代码

class Xhprof
{
    /**
     * 监控开始
     */
    public function start()
    {
        xhprof_enable();
    }

    /**
     * 监控结束
     */
    public function end()
    {
        // stop profiler
        $xhprof_data = xhprof_disable();
        $XHPROF_ROOT = realpath(dirname(__FILE__) . '/../../../xhprof-0.9.4');
        include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
        include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
        $xhprof_runs = new XHProfRuns_Default();
        $id = $xhprof_runs->save_run($xhprof_data, 'newdefend');
        //$CI =& get_instance();
        echo "<a href='http://localhost/xhprof-0.9.4/xhprof_html/index.php?run=" . $id . "&source=newdefend' target=_blank>查看监控</a>";
    }
}
原文地址:https://www.cnblogs.com/qq917937712/p/8889433.html