XHPROF相關內容

來源:互聯網
上載者:User

標籤:目錄   sts   open   blog   載入   false   register   nbsp   root   

定義入口檔案

define(‘XHPROF_OPEN‘, 0);define(‘XHPROF_ROOT‘, ‘/home/www/xhprof/‘);// 開啟偵錯模式 建議開發階段開啟 部署階段注釋或者設為falsedefine(‘APP_DEBUG‘,true);// 定義應用目錄define(‘APP_PATH‘,‘../app/‘);define(‘LOG_PATH‘,APP_PATH.‘Runtime/Logs/‘);if(defined(‘XHPROF_OPEN‘) && XHPROF_OPEN) {    require (‘./xhprof.php‘);}

 

載入xhprof.php

 

<?phpif (!defined(‘XHPROF_OPEN‘)) define(‘XHPROF_OPEN‘, 0);class Xhprof{    private static $st = 0;    /**     * [start description]     * @return [type] [description]     */    public static function start()    {        if (!function_exists(‘xhprof_enable‘)) {            exit("xhprof_enable not exists!");        }         if (!is_dir(XHPROF_ROOT)) {            exit(XHPROF_ROOT . " not exists!");        }        //xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);        xhprof_enable(XHPROF_FLAGS_NO_BUILTINS |XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);        self::$st = microtime(true);        register_shutdown_function(array(__CLASS__, ‘end‘)); //php進程關閉時自動執行的方法    }    /**     * [end description]     * @return [type] [description]     */    public static function end()    {        $et = microtime(true);        $data = xhprof_disable();        include_once XHPROF_ROOT."xhprof_lib/utils/xhprof_lib.php";        include_once XHPROF_ROOT."xhprof_lib/utils/xhprof_runs.php";        $runs = new XHProfRuns_Default();        $runId = $runs->save_run($data, "hx");        $log = XHPROF_ROOT . ‘xhprof_html/logs/‘.date(‘YmdHis‘).‘.html‘;        $cost = $et - self::$st;        $host = $_SERVER[‘HTTP_HOST‘];        $title = $_SERVER[‘REQUEST_URI‘];        $content = ‘Time: ‘.date(‘H:i:s‘)."\tCost: {$cost}\t\tUri({$host}): <a href=‘/index.php?run={$runId}&source=hx‘ target=‘_blank‘>{$title}</a><br/>";        file_put_contents($log, $content, FILE_APPEND);    }}if(XHPROF_OPEN) Xhprof::start();

 

XHPROF_OPEN 調試為1就可用

 

XHPROF相關內容

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.