XhProf是Facebook出品的一个PHP性能监控工具,只包含基本的界面和图形来分析数据。后来Paul Reinheimer在此基础上开发了Xhgui,提供了更好的界面和功能,其主页在https://github.com/perftools/xhgui,其实步骤说的很详细,但是在CentOS7上安装并不容易,因为很多程序需要编译,在这里记录一下
安装
yum install mongodb-org
systemctl enable mongod
systemctl start mongod
16、mcrypt
cd ~/download
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar xvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
cd ~/download
wget http://museum.php.net/php5/php-5.4.16.tar.gz
cd php-5.4.16/ext/mcrypt/
phpize
./configure
make
make install
vim /etc/php.ini
最后增加
extension=mcrypt.so
用php -m验证
17、Dom
cd ~/download/php-5.4.16/ext/dom/
yum install libxml2-devel
phpize
./configure
make
make install
vim /etc/php.ini
最后增加
extension=dom.so
用php -m验证
19、配置nginx,将xhgui放在88端口
vim /usr/local/nginx/conf/nginx.conf
增加
<?php
$n=5000;
$a = createArray($n);
$a = sortArray($a);
echoArray($a);
function createArray($n){
$a;
for($i=0;$i<$n;$i++){
$a[$i]=rand(0,$n);
}
return $a;
}
function echoArray($a){
for($i=0;$i<count($a);$i++){
echo $a[$i]." ";
}
}function sortArray($a){
for($i=0;$i<count($a);$i++){
for($j=$i+1;$j<count($a);$j++){
if($a[$i]<$a[$j]){
$tmp = $a[$i];
$a[$i]=$a[$j];
$a[$j]=$tmp;
}
}
}
return $a;}其实很简单,就是一个创建数组,进行排序的过程,可以在浏览器中运行http://172.16.9.145/test.php,理论上就可以在http://172.16.9.145:88看到结果了,但是,刷新88端口,一般是看不到结果的,这里是一个采样问题,xhgui是按照1%采样的,所以对于开发来说,需要100%采样,需要修改vim /data/xhgui/config/config.php'profiler.enable' => function() {//return rand(0,100) == 42return rand(0, 100) > 0 ;},黑体子是修改内容,这就是100%的采样,再运行http://172.16.9.145/test.php,就可以在http://172.16.9.145:88上看到结果了,可以看到采样的结果,包括程序的等待时间(wt)、cpu时间、内存等等信息,还可以通过view Graphy看到函数调用的过程,颜色越深,说明运行越慢,需要处理。23、其他
xhgui使用mongodb保存性能数据,数据库连接信息保存在xhgui/config/config.php中,这意味着可以将性能信息保存到远程机器,还可以将多台机器的性能数据放在一起,我们可以看一下性能数据的结构,如下mongo>use xhprof>db.results.find().limit(1).pretty();查看一下键meta的信息,如下"meta" : {"url" : "/test.php","SERVER" : {"USER" : "apache","HOME" : "/usr/share/httpd","FCGI_ROLE" : "RESPONDER","SCRIPT_FILENAME" : "/data/html/test.php","QUERY_STRING" : "","REQUEST_METHOD" : "GET","CONTENT_TYPE" : "","CONTENT_LENGTH" : "","SCRIPT_NAME" : "/test.php","REQUEST_URI" : "/test.php","DOCUMENT_URI" : "/test.php","DOCUMENT_ROOT" : "/data/html","SERVER_PROTOCOL" : "HTTP/1.1","REQUEST_SCHEME" : "http","GATEWAY_INTERFACE" : "CGI/1.1","SERVER_SOFTWARE" : "nginx/1.9.9","REMOTE_ADDR" : "172.16.9.255","REMOTE_PORT" : "62433","SERVER_ADDR" : "172.16.9.145","SERVER_PORT" : "80","SERVER_NAME" : "localhost","REDIRECT_STATUS" : "200","PHP_VALUE" : "auto_prepend_file=/data/xhgui/external/header.php","HTTP_HOST" : "172.16.9.145","HTTP_CONNECTION" : "keep-alive","HTTP_CACHE_CONTROL" : "max-age=0","HTTP_ACCEPT" : "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8","HTTP_UPGRADE_INSECURE_REQUESTS" : "1","HTTP_USER_AGENT" : "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36","HTTP_ACCEPT_ENCODING" : "gzip, deflate, sdch","HTTP_ACCEPT_LANGUAGE" : "zh-CN,zh;q=0.8","HTTP_COOKIE" : "slim_session=1450653227%7CBxhI8%2BKm%2B47xsnTB%2BOZVAv9qjPHQYC1oCIcfWhIblGI%3D%7C3a5b1cf4f47a77302d253b577949544f4ffe627b","PHP_SELF" : "/test.php","REQUEST_TIME_FLOAT" : 1450652599.176433,"REQUEST_TIME" : NumberLong(1450652599)},可以通过SERVER_*, HTTP_*看到服务器信息,可以用来区分不同的主机,所以可以通过这些信息来过滤,可以支持多个主机