PHP 性能分析工具XHProf使用
来自: http://blog.csdn.net//clh604/article/details/21934453
当php程序逻辑执行很复杂的时候,可能会带来性能上的问题,为了有效的找到影响性能的代码,推荐大家使用PHP新能分析工具XHProf,该工具能有效的分析每段代码的执行情况,非常好用
1、安装配置PHP的扩展XHProf
$ wget https://github.com/facebook/xhprof/tarball/master -O xhprof.tar.gz$ tar zxf xhprof.tar.gz$ cd facebook-xhprof-b8c76ac/extension/# phpize# ./configure --with-php-config=`/path/to/php-config`# make && make install# make test# vi /etc/php.d/xhprof.ini; 内容为:extension = xhprof.so; 注意:output_dir 必须存在且可写xhprof.output_dir = /tmp/xhpro然后重启apache服务# service php-fpm restart 或 service httpd restart
2、使用XHProf
// start profilingxhprof_enable();// run program....// stop profiler$xhprof_data = xhprof_disable();//// Saving the XHProf run// using the default implementation of iXHProfRuns.//include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";$xhprof_runs = new XHProfRuns_Default();// Save the run under a namespace "xhprof_foo".//// **NOTE**:// By default save_run() will automatically generate a unique// run id for you. [You can override that behavior by passing// a run id (optional arg) to the save_run() method instead.]//$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo");echo "---------------\n"."Assuming you have set up the http based UI for \n"."XHProf at some address, you can view run at \n"."http://<xhprof-ui-address>/index.php?run=$run_id&source=xhprof_foo\n"."---------------\n";如此一来,会在上面设定的xhprof.output_dir目录里生成名字类似49bafaa3a3f66.xhprof_foo的数据文件,可以很方便的通过Web方式浏览效果:
3、展示输出结果
在 xhprof 源码包中提供了xhprof_html 和 xhprof_lib 两个文件夹,xhprof_lib是用于 PHP 开发,而xhprof_html用于显示 xhprof 分析结果的 web 界面,访问形式如下

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building
