search
Homephp教程php手册【转】给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof,性能测试xhprof

【转】给Windows + Apache 2.2 + PHP 5.3 安装PHP性能测试工具 xhprof,性能测试xhprof

原文链接:http://blog.snsgou.com/post-816.html

 

1、下载XHProf

到这里 http://dev.freshsite.pl/php-extensions/xhprof.html 下载Windows版本的XHProf,我这里选择下载

XHProf 0.10.3 for PHP 5.3 vc9 和 xhprof_html

 

2、安装XHProf

把压缩包里的 xhprof_0.10.3_php53_vc9.dll 拷贝到PHP的ext目录下,然后在php.ini配置里面加入配置(不要忘记创建对应的文件夹)

[xhprof]
extension=xhprof_0.10.3_php53_vc9.dll
; directory used by default implementation of the iXHProfRuns
; interface (namely, the XHProfRuns_Default class) for storing
; XHProf runs.
xhprof.output_dir="d:/PHP/xhprof/log"

  

3、使用XHProf

 xhprof_html.zip 解压到你想测试的网站根目录,如我放在了网站目录的 /public/xhprof/windows 下。

测试文件:

<?php
function bar($x)
{
	if ($x > 0)
	{
		bar($x - 1);
	}
}

function foo()
{
	for ($idx = 0; $idx < 5; $idx++)
	{
		bar($idx);
		$x = strlen("abc");
	}
}

// 启动xhprof
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

// 调用foo函数,也是我们要分析的函数
foo();

// 停止xhprof

$xhprof_data = xhprof_disable();

// 取得统计数据
//print_r($xhprof_data);

$os = 'windows';

$XHPROF_ROOT = dirname(__FILE__) . '/public/xhprof/' . $os;
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";

// 保存统计数据,生成统计ID和source名称
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, "xhprof_foo"); // source名称是xhprof_foo

// 查看统计信息
echo "<div style='margin: 50px auto; padding :10px; width: 92px; font-size: 16px; background: #ff0000;'><a style='color:#ffff00;' href='/public/xhprof/" . $os . "/xhprof_html/index.php?run=" . $run_id . "&source=xhprof_foo' target='_blank'>XHProf view</a></div>";

  

当点击链接“[View Full Callgraph]”时,会报错:

<p>failed to execute cmd: " dot -Tpng"</p>

所以还需要下载图形工具 Graphviz

 

 

4、下载Graphviz

到这里 http://www.graphviz.org/Download_windows.php 下载Windows版本的Graphviz,我这里选择下载  

graphviz-2.38.zip

 

5、安装Graphviz

解压后,把Graphviz拷贝到某个目录,如 d:/PHP/xhprof/graphviz-2.38/

 

6、配置Graphviz

找到上述提到网站目录 /public/xhprof/windows/ 下的 config.php 文件,调整如下:

<?php
/**
 * Set the absolute paths on your system
 */
define('ERROR_FILE', 'd:/PHP/xhprof/log/xhprof_dot_errfile.log');
define('TMP_DIRECTORY', 'd:/PHP/xhprof/tmp');
define('DOT_BINARY', 'd:/PHP/xhprof/graphviz-2.38/release/bin/dot.exe');

  重新点击链接 [View Full Callgraph],一张期待已久的效果图出来啦:

 

 

 

Statement
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.