Analysis Method of PHP code performance

Source: Internet
Author: User

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 graphically structured. The premise is that you installed the GD library, you may also encounter some minor problems. I remember to update the Linux image Library.

Install xhprof extension: pecl install xhprof.

<?php


/**


 *


 *


* Beck Confidential


* Copyright (c) 2013, Beck Corp. <BECK.BI>


* 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 ();


    /**


* Configure your xhprof you can see a description of the application on the website of PHP


* @param unknown $config


* @throws extensionnotfoundexception


     */


Public function __construct ($config = Array ())


    {


if (!extension_loaded (' xhprof ')) {


throw new Extensionnotfoundexception (


' Configuration error! Make sure your 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 '];


        }


    }


    /**


* Open Debugging


     */


Public function enable ()


    {


xhprof_enable ($this->flags, $this->options);


    }


Public function Disable ()


    {


$this->xhprofdata = xhprof_disable ();


    }


    /**


* Display debug Results


* You may need to configure a apache/ nginx Virtual 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 "<a href= ' http://pear.kang.com/xhprof_html/index.php?run={$run _id}&source=xhprof_testing ' target= ' _blank ' >see xhprof result</a> ';


    }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.