Esempio n. 1
0
function xhprof_write($job)
{
    $data = unserialize($job->workload());
    $xhprof_run = new XHProfRuns_DB();
    $run_id = $xhprof_run->save_run($data);
    echo "gearman save id: {$run_id}\n";
}
Esempio n. 2
0
function xhprof_stop()
{
    // 关闭xhprof
    global $gearman_enabled;
    $error = error_get_last();
    $resp_time = sprintf("%.4f", $GLOBALS['AX_PAGE_END_TIME'] - $GLOBALS['AX_PAGE_START_TIME']);
    if (!empty($error) || $GLOBALS['AX_XHPROF_IS_RUN'] || $resp_time >= $GLOBALS['AX_XHPROF_TIMEOUT']) {
        $data = array();
        $data['host'] = $_SERVER['HTTP_HOST'];
        $data['uri'] = $_SERVER['REQUEST_URI'];
        $data['client_time'] = date('Y-m-d H:i:s');
        $data['resp_time'] = $resp_time;
        $data['xhprof'] = null;
        if ($GLOBALS['AX_XHPROF_IS_RUN']) {
            $data['xhprof'] = xhprof_disable();
            $GLOBALS['AX_XHPROF_IS_RUN'] = false;
        }
        $data['error'] = $error;
        // 检查是否安装gearman扩展,并已设置gearman server
        if ($gearman_enabled) {
            $ret = do_background_job('xhprof.write', serialize($data));
            echo "\n<!-- gearman save: {$ret} -->\n";
        } else {
            $xhprof_run = new XHProfRuns_DB();
            $run_id = $xhprof_run->save_run($data);
            echo "\n<!-- xhprof save, id: {$run_id} -->\n";
        }
    }
}