Install and use PHP performance testing tool xhprof
Recently, I want to compare the performance of my website, so I am looking for a performance testing job to play with a lot of tools, but I still think that the installation and use of xhprof is relatively simple compared with the previous one, data analysis is also acceptable. next we will talk about its installation and use...
Download xhprof and graphviz
Xhprof can be downloaded directly from the php official website.
Graphviz also needs to be downloaded. it is mainly a graphical report that displays xhprof performance results.
Compile and install xhprof
cd xhprof-0.9.4/xhprof-0.9.4/extension/phpize./configuremakesudo make install
Add the generated xhprof. so file to the php. ini file, and restart apache.
... # If you want to use the relative path for loading, you should first look at the path configured by extension_dir, or directly write the '. so' file to the absolute path... Extension = xhprof. so... sudo apachectl restart # test whether the extension is successfully installed. if the following output is displayed, okphp -- ri xhprof... xhprof => 0.9.2 CPU num => 4...
Install graphviz
Cd graphviz-2.38.0/# The following parameters are to ensure that libphp is installed Oh [not installed brew install linpng can be]./configure -- with-png = yesmakesudo make install
Tested
In the previously downloaded xhprof folder, find the xhprof_html, xhprof_lib, and sample folders. put these three folders in the accessible places, and then access the following http through the connection: // xxxx/sample. php: When you access the following http: // xxxx/xhprof_html/, a record is displayed. after you click it, the analysis result page is displayed, click View Full CallGraph to link to the graph report page.
How to use
Suppose you want to check the performance data of a website's homepage, you need to find the homepage entry file of the website and add the xhprof performance test code before and after loading the core file.
# Enable. For more information about the parameters, see the official documentation xhprof_enable (XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY). # run the core file... require 'index. php '... # Disable $ xhprof_data = xhprof_disable (); # configure $ XHPROF_ROOT = realpath (dirname (_ FILE _) based on your website __). '/'); include_once $ XHPROF_ROOT. "/xhprof_lib/utils/xhprof_lib.php"; include_once $ XHPROF_ROOT. "/xhprof_lib/utils/clusters"; $ xhprof_runs = new XHProfRuns_Default (); $ run_id = $ xhprof_runs-> save_run ($ xhprof_data, "xhprof "); # print the id of this test, and go to the report list page [http: // xxxx/xhprof_html/] to find the corresponding result var_dump ($ run_id) through the corresponding id );