<?php //var_dump(function_exists("register_shutdown_function")); //根据参数控制是否开启xhprof if ((rand(1, 100) >= 1 || !empty($_GET['xhprof'])) && PHP_SAPI != 'cli' && function_exists('xhprof_enable')) { //(rand(1, 100) 控制采样率 !defined('DEBUG_LIB') && define("DEBUG_LIB", "/data/www/xhprof/xhprof_lib"); //根据你存放的目录修改 include_once DEBUG_LIB . "/utils/xhprof_lib.php"; include_once DEBUG_LIB . "/utils/xhprof_runs.php"; xhprof_enable(XHPROF_FLAGS_NO_BUILTINS + XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); register_shutdown_function(function() { //stop profiler if (!function_exists("xhprof_disable")) { return ; } $xhprof_data = xhprof_disable(); $wt = isset($xhprof_data['main()']['wt']) ? $xhprof_data['main()']['wt'] : 0; $client_id = empty($_SERVER['HTTP_X_AKAM_CLIENTID']) ? '' : $_SERVER['HTTP_X_AKAM_CLIENTID']; if ($wt <= 2000000 && empty($_GET['xhprof'])) { return ; } //冲刷(flush)所有响应的数据给客户端 $xhprof_runs = new XHProfRuns_Default(); //save the run under a namespace "xhprof_foo" $uri = $_GET['xhprof'] . '-' . $client_id . '-wt:' . round($wt * 0.001) . '-' . $_SERVER['HTTP_HOST'] . $_SERVER['PATH_INFO']; $uri = str_replace(['/', '.', '\\', '|'], '_', $uri); $xhprof_runs->save_run($xhprof_data, $uri); }); }
标签:function,LIB,nginx,wt,DEBUG,xhprof,data,加载 From: https://www.cnblogs.com/jinshao/p/14103131.html