PHP代码性能的分析方法_PHP教程

WBOY
发布: 2016-07-13 10:22:11
原创
1209 人浏览过

PHP代码性能的分析方法

 php代码的性能分析。

你可以用xdbug去分析。

但是更好的选择是facebook的性能分析工具xhprof。

它可以图形化。前提是你安装了gd库,你也可能遇到一些小问题。我记得要更新linux的图像库。

安装xhprof扩展:pecl install xhprof .


/**
 *
 *
 * Beck Confidential
 * Copyright (c) 2013, Beck Corp. .
 * All rights reserved.
 *
 * PHP version 5
 *
 * @category  Aug
 * @package package_name
 * @author beck
 * @date 2013-8-13
 * @license
 * @link
 *
 */
class Xhprof
{
    protected $flags = 0;
    protected $options = array();
    protected $xhprofData = array();
    /**
     * 配置你的xhprof 你可以在php的官网看着个应用的说明
     * @param unknown $config
     * @throws ExtensionNotFoundException
     */
    public function __construct($config = array())
    {
        if (!extension_loaded('xhprof')) {
            throw new ExtensionNotFoundException(
                'Configuration error! Make sure you have xhprof installed correctly.
                please refer http://www.php.net/manual/en/xhprof.examples.php for detail.'
            );
        }
        if (!empty($config['flags'])) {
            $this->flags = (int)$config['flags'];
        }
        if (!empty($config['options'])) {
            $this->options = $config['options'];
        }
    }
    /**
     * 开启调试
     */
    public function enable()
    {
        xhprof_enable($this->flags, $this->options);
    }
    public function disable()
    {
        $this->xhprofData =  xhprof_disable();
    }
    /**
     *显示调试结果
     * 你可能需要配置一个apache/nginx虚拟主机
     */
    public function show()
    {
        $this->disable();
        include_once "xhprof_lib/utils/xhprof_lib.php";
        include_once "xhprof_lib/utils/xhprof_runs.php";
        $xhprof_runs = new XHProfRuns_Default();
        $run_id = $xhprof_runs->save_run($this->xhprofData, "xhprof_testing");
        echo "see xhprof result";
    }
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/850927.htmlTechArticlePHP代码性能的分析方法 php代码的性能分析。 你可以用xdbug去分析。 但是更好的选择是facebook的性能分析工具xhprof。 它可以图形化。前提是...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!