Use xhprof for online PHP performance tracking and analysis
WBOYOriginal
2016-08-08 09:29:531032browse
I have been using Xdebug for PHP performance analysis before, which is sufficient for local development environments. However, if it is an online environment, xdebug consumes a lot of money and the configuration is not flexible enough. Therefore, it is recommended to use xhprof for PHP in online environments. Performance tracking and analysis. xhprof installation and easy usagexhprof is Facebook’s open source lightweight PHP performance analysis tool. It can be installed directly through pecl in Linux environment. For example, under Ubuntu, it only requires 3 lines of instructions pecl install xhprof-beta
echo "extension=xhprof.so" > /etc/php5/fpm/conf.d/xhprof.ini
service php5-fpm restart and then it can be installed through phpinfo() Check if the extension has been loaded. How to use it specifically? The xhprof project has provided examples and simple UI. Download the xhprof project to the web server. If it can be accessed through http://localhost/xhprof/, then visit http://localhost/ xhprof/examples/sample.phpYou can see some output, and you are prompted to view the results by visiting http:///index.php?run=XXX&source=xhprof_foo. Next, visit http://localhost/xhprof/xhprof_html/ to see the saved results, listing all function calls and the time spent. Analyze the sample code sample.php. The key part is only 2 lines: //开启xhprof并开始记录
xhprof_enable();
//运行一些函数
foo();
//停止记录并取到结果$xhprof_data = xhprof_disable();
$xhprof_data records all the function call time and CPU memory consumption during the single-step running of the program. What indicators can be recorded specifically? Through the entry parameter control of xhprof_enable, the subsequent processing has nothing to do with the xhprof extension. Basically, a storage class XHProfRuns_Default is written to serialize and save $xhprof_data to a certain directory, which can be done through XHProfRuns_Default(__DIR__) Output the results to the current directory. If not specified, xhprof.output_dir in the php.ini configuration file will be read. If still not specified, it will be output to /tmp. xhprof_html/index.php Organize and visualize the recorded results. The default UI lists:
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