PHP Performance analysis tool XHPROF installation Tutorial

Source: Internet
Author: User

This article mainly introduces PHP performance analysis tool xhprof installation tutorial, this article gives detailed installation steps and configuration methods as well as the use of examples, the need for friends can refer to the

Hprof is a PHP lightweight performance analysis tool for Facebook, which is similar to Xdebug, but has a lower performance cost, can be used in a production environment, and can be controlled by a program switch. Based on browsing

Performance Analysis user interface can be easier to view, or share the results with peers. You can also draw the call graph. During the data collection phase, it records the number of calls traced and an inclusive indicator arc in the dynamic callgraph of a program.

It uniquely calculates the report/post processing phase of the data. In data collection, XHPROFD processes recursive function calls by detecting loops and avoids dead loops by giving a useful name to each depth call in a recursive call.

The lightweight nature of the xhprof and the convergence feature make it ideal for collecting statistics on performance statistics for the production environment.

1. Install Xhprof

The code is as follows:

wget http://pecl.php.net/get/xhprof-0.9.2.tgz

Tar zxf xhprof-0.9.2.tgz

CD xhprof-0.9.2

Cp-r xhprof_html Xhprof_lib

CD extension

Phpize

./configure

Make

Make install

2. Configure php.ini files

The code is as follows:

[Xhprof]

Extension=xhprof.so

;

; Directory used by default implementation of the Ixhprofruns

; Interface (namely, the Xhprofruns_default Class) for storing

; Xhprof runs.

; Remember that the Web has write permissions

Xhprof.output_dir=

Restart the service so that the changes take effect, you can now use Xhprof, but in order to show the effect is more dazzling, it is best to continue to install Graphviz.

3. Install Graphviz

The code is as follows:

wget http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.26.3.tar.gz

Tar zxf graphviz-2.26.3.tar.gz

CD graphviz-2.26.3

./configure

Make

Make install

When the installation is complete, the/usr/local/bin/dot file is generated, and you should make sure that the path is in the paths environment variable so that xhprof can find it.

4. Application Xhprof

Copy code code as follows:

Xhprof_enable ()//Open Xhprof

/****** program Logic start******/

function Test1 () {

Sleep (3);

Return

}

function Test2 () {

Test1 ();

}

function Test3 () {

Test2 ();

}

function P () {

Echo '

Xhprof Test

';

}

P ();

Test3 ();

/****** program Logic end******/

$xhprof _data = xhprof_disable ();//Close Xhprof

Save Xhprof Data

Include_once '.. /xhprof_lib/utils/xhprof_lib.php ';

Include_once '.. /xhprof_lib/utils/xhprof_runs.php ';

$xhprof _runs = new Xhprofruns_default ();

$xhprof _source = ' xhprof_test ';

$run _id = $xhprof _runs->save_run ($xhprof _data, $xhprof _source);

$report _url = ' http://xhprof.rebill.info/index.php?run= '. $run _id. ' &source= '. $xhprof _source;

Echo '
';

Echo ' View the performance: '. $report _url. ';

In this way, the Xhprof.output_dir directory will be created in the above name similar to 4c236583ef490.xhprof_test data files, it is easy to browse through the Web effect:

Http://xhprof.rebill.info/index.php?run=4c236583ef490&source=xhprof_test

Currently displayed in tabular form, click on the [View full CallGraph] on the page to see the beautiful picture displayed.

Online Test experience Address: http://xhprof.rebill.info/test.php

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.