Home Backend Development PHP Tutorial Xhprof php性能测试用具用法小结

Xhprof php性能测试用具用法小结

Jun 13, 2016 am 10:41 AM
nbsp php protected quot

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
Copy after login

通过上面的操作,如果运气不是非常糟糕的话,你应该看到类似这样的提示: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
Copy after login

重启下php,就可以在使用xhprof了。

3、拷贝文件

把xhprof-0.9.2目录下的目录xhprof_html 和 xhprof_lib 下的所有文件拷贝到你网站的主目录下,假设网站主目录:/opt/wordpress

[[email&#160;protected] xhprof-0.9.2]# cp -R xhprof_* /opt/wordpress
Copy after login

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";
Copy after login

      在浏览器中打开输出的url,及可看到相关的性能信息。

 

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

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

See all articles