Home > Backend Development > PHP Tutorial > Analysis method of PHP code performance_PHP tutorial

Analysis method of PHP code performance_PHP tutorial

WBOY
Release: 2016-07-13 10:22:11
Original
1273 people have browsed it

How to analyze the performance of PHP code

Performance analysis of PHP code.

You can use xdbug to analyze.

But a better choice is facebook’s performance analysis tool xhprof.

It can be done graphically. The premise is that you have the gd library installed, you may also encounter some minor problems. I remember to update the linux image library.

Install xhprof extension: 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();
    /**
* To configure your xhprof, you can read the application instructions on the official website of 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'];
        }
    }
    /**
* Enable debugging
*/
    public function enable()
    {
        xhprof_enable($this->flags, $this->options);
    }
    public function disable()
    {
        $this->xhprofData =  xhprof_disable();
    }
    /**
*Show debugging results
* You may need to configure an apache/nginxvirtual host
*/
    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 code performance analysis method PHP code performance analysis. You can use xdbug to analyze. But a better choice is Facebook's performance analysis tool xhprof. It can be done graphically. The premise is...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template