安装 mongodb扩展
pecl install mongodb
[mongodb]
extension=mongodb.so
安装 tideaways扩展
https://github.com/tideways/php-xhprof-extension
git clone
phpize
./configure
make
make install
[tideways]
extension=tideways_xhprof.so
;不需要自动加载,在程序中控制就行
tideways.auto_prepend_library=0
;频率设置为100,在程序调用时能改
tideways.sample_rate=100
重启php
/etc/init.d/php-fpm restart
安装 mongodb
vim /etc/yum.repos.d/mongodb-org-3.2.repo
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
yum -y install mongodb-org
/etc/init.d/mongod start
安装 xhgui
git clone https://github.com/laynefyc/xhgui-branch.git
cd xhgui-branch
composer install –prefer-dist
# 配置文件
config/config.default.php
‘extension’ => ‘tideways_xhprof’,
# 入口文件增加时区设置
date_default_timezone_set(“Asia/Shanghai”);
测试 MongoDB连接情况并优化索引
use xhprof
db.results.ensureIndex( { ‘meta.SERVER.REQUEST_TIME’ : -1 } )
db.results.ensureIndex( { ‘profile.main().wt’ : -1 } )
db.results.ensureIndex( { ‘profile.main().mu’ : -1 } )
db.results.ensureIndex( { ‘profile.main().cpu’ : -1 } )
db.results.ensureIndex( { ‘meta.url’ : 1 } )
配置nginx
# UI访问地址
server {
listen 80;
server_name x.fengfeng.com;
root /data/www/xhgui-branch/webroot;
location / {
index index.php;
if (!-e $request_filename) {
rewrite . /index.php last;
}
}
location ~ \.php$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
access_log /data/logs/x.fengfeng.com.log access;
}
# 在 fastcgi_param 中添加 auto_prepend_file
location ~ [^/]\.php(/|$)
{
fastcgi_param PHP_VALUE “auto_prepend_file=/data/www/xhgui-branch/external/header.php”;
}