CentOS使用yum安装php性能测试工具xhprof

WBOY
Release: 2016-06-23 13:40:24
Original
999 people have browsed it

1.首先我们安装xhprof:

yum install xhprof
Copy after login


2.安装好之后,找到xhprof的配置文件xhprof.conf,一般会在/etc/php.d里面,加入这2行:

extension=xhprof.soxhprof.output_dir=<directory_for_storing_xhprof_runs>
Copy after login

该路径是指把生成的数据放到哪的文件夹,例如放在/var/www/html/xhprof_data


3.如果要图形话,需要安装dot(可选):

yum install graphviz
Copy after login


4.安装好之后重启一下服务器:

service httpd restart
Copy after login


5.使用的话只要包含以下文件代码即可:

#在php的头部加上,可以设置记录频率,比如记录万分之一xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
Copy after login
#在代码页的底部加上if ($xhprof_flag) {    $xhprof_data = xhprof_disable();    include_once "./xhprof_lib/utils/xhprof_lib.php";    include_once "./xhprof_lib/utils/xhprof_runs.php";    $xhprof_runs = new XHProfRuns_Default();    $xhprof_runs->save_run($xhprof_data, 'xhprof',"index_".time());}
Copy after login

上面的xhprof_lib,php和xhprof_runs.php这2个文件的路径要改成自己的路径,千万不要写错,如果找不到这两个文件,可以使用指令 whereis xhprof 该指令会把xhprof相关的路径都罗列出来,你可以一一查询。?


6.把xhprof_html文件夹拷贝到你的web服务器根目录下,用来访问那些生成的文件;当有该php的访问时,会在目录下生成类似index_1277956324.xhprof的记录文件,使用类似 http://www.url.com/xhprof_html/index.php?run=index_1277956324,就可以看到结果。也可以http://www.url.com/xhprof_html/index.php访问文件目录,然后选择任意一个进行查看。

source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template