zoukankan      html  css  js  c++  java
  • PHP程序性能分析 XHProf

    XHProf 用于检测每个函数的调用,运行时间等情况

    安装:

    wget http://pecl.php.net/get/xhprof-0.9.2.tgz
    tar zxf xhprof-0.9.2.tgz
    cd xhprof-0.9.2
    /usr/local/php/bin/phpize
    ./configure -with-php-config=/usr/local/php/bin/php-config
    make && make install
    vi /usr/local/php/etc/php.ini 
    #添加编译好的入配置
    kill -SIGUSR2 `cat /usr/local/php/var/run/php-fpm.pid`
    #增加线性图工具
    wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.24.0.tar.gz
    tar zxf graphviz-2.24.0.tar.gz
    cd graphviz-2.24.0
    ./configure
    make && make install
    #拷贝 xhprof-0.9.2 到你的项目

    使用

    <?php
    xhprof_enable();
    xhprof_enable(XHPROF_FLAGS_NO_BUILTINS); //不记录内置的函数
    xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); //记录的情况
    $xhprof_on = true;
    
    //your are code!!!
    
    
    if($xhprof_on){
    $xhprof_data = xhprof_disable();
    $xhprof_root = dirname(__FILE__)."/";
    include_once $xhprof_root."xhprof/xhprof_lib/utils/xhprof_lib.php";
    include_once $xhprof_root."xhprof/xhprof_lib/utils/xhprof_runs.php";
    $xhprof_runs = new XHProfRuns_Default();
    $key="onlykey";
    $run_id = $xhprof_runs->save_run($xhprof_data, $key);
    echo '<a href="/xhprof/xhprof_html/index.php?run='.$run_id.'&source='.$key.'">统计</a>';
    }

    据说分析省资源,但生成环境还是别用.测试环境可以加上.找到瓶颈

    composer 配置

    "facebook/xhprof": "dev-master"

    之后 php composer.phar update 即可,更方便

  • 相关阅读:
    vue中minxin---小记
    微信认证
    Fatal error Using $this when not in object context in
    $.ajax()方法详解
    $.post
    jquery中的each
    jquery的$.extend和$.fn.extend作用及区别
    javascript字符串函数
    serializeArray()与serialize()的区别
    一个登陆界面
  • 原文地址:https://www.cnblogs.com/liushannet/p/2832054.html
Copyright © 2011-2022 走看看