Xhprof php性能测试用具用法小结
Xhprof php性能测试工具用法小结
Xhprof 是facebook推出的轻量级的php性能分析工具,和Xdebug相比,XHProf更加易用和可控,尤其是生成流程图和调试数据对比的功能很好很强大。 下面简单介绍下Xhprof的安装及使用。
1、安装
可以从页面 下载相应版本及了解各个版本依赖条件。 安装前,先假设php的bin目录是:/usr/local/php/bin
[[email protected] extension]# ln -s /usr/local/php/bin/phpize /usr/bin/phpize[[email protected] tool]# wget http://pecl.php.net/get/xhprof-0.9.2.tgz[[email protected] tool]# tar -zxvf xhprof-0.9.2.tgz [[email protected] tool]# cd xhprof-0.9.2/extension/[[email protected] tool]# ./configure --with-php-config=/usr/local/php/bin/php-config[[email protected] tool]# make[[email protected] tool]# make install
通过上面的操作,如果运气不是非常糟糕的话,你应该看到类似这样的提示:Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/
进入到php扩展库目录/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/ ,你将看到xhprof.so 共享库文件。
2、配置
在php.ini文件中,添加如下配置:
[xhprof]extension=xhprof.so;; directory used by default implementation of the iXHProfRuns; interface (namely, the XHProfRuns_Default class) for storing; XHProf runs.;;xhprof.output_dir=<directory_for_storing_xhprof_runs>xhprof.output_dir=/tmp/xhprof
重启下php,就可以在使用xhprof了。
3、拷贝文件
把xhprof-0.9.2目录下的目录xhprof_html 和 xhprof_lib 下的所有文件拷贝到你网站的主目录下,假设网站主目录:/opt/wordpress
[[email protected] xhprof-0.9.2]# cp -R xhprof_* /opt/wordpress
4、使用
参考下面的解释说明:
<?php//cpu: XHPROF_FLAGS_CPU//内存: XHPROF_FLAGS_MEMORY//如果都监控用XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORYxhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);//需要性能分析的php代码//define('WP_USE_THEMES', true);//require('./wp-blog-header.php');//停止性能分析$data = xhprof_disable(); //显示性能分析数据include_once "xhprof_lib/utils/xhprof_lib.php"; include_once "xhprof_lib/utils/xhprof_runs.php"; $objXhprofRun = new XHProfRuns_Default(); //第一个参数 是xhprof_disable()的返回值//第二个参数 是自定义命名空间字符串 //返回运行id,用这个id查看相关运行结果$run_id = $objXhprofRun->save_run($data, "xhprof"); //查看运行结果的url//run的值来源于save_run的返回值//source值来源于save_run的第二个参数 //www.abc.com 需要用自己的域名替换echo "http://www.abc.com/xhprof_html/index.php?run=".$run_id."&source=xhprof";
在浏览器中打开输出的url,及可看到相关的性能信息。

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

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.
