Home >Backend Development >PHP Tutorial >PHP performance analysis platform construction
Build a PHP performance analysis platform without changing your program Code, use nginx to add a monitoring layer on top of your program (to produce fixed logs), analyze the program information of the log, and perform performance analysis and optimization
Omit 1000 words here, find the document yourself
wget http://pecl.php.net/get/mongodb-1.4.0.tgz tar -zxvf mongodb-1.4.0.tgz cd mongodb-1.4.0 phpize ./configure --with-php-config=你的php-config路径 我的是在/usr/local/Cellar/php@7.1/7.1.16_1/bin/php-config make make install
git clone https://github.com/tideways/php-profiler-extension.git cd php-profiler-extension phpize ./configure --with-php-config=你的php-config路径 make make install
extension=tideways.so tideways.auto_prepend_library=0 extension=mongodb.so
#https://github.com/perftools/xhgui (汉化) git clone https://github.com/perftools/xhgui.git cd xhgui php install.php(看下是否有vendor这个目录) ##项目配置 #配置文件:config/default_config.php #运行目录:webroot #nginx rewrite规则 # location / { # try_files $uri $uri/ /index.php$is_args$query_string; # }
#xhgui 默认是采集1% ,如果是排查问题时还是希望能够100%采集会比较方便。进入xhgui源码目录,修改config/config.default.php文件, #平时仍然按1%的采样率采样,防止数据增长过快,当想调试时,就在URL中添加debug=1的参数即可。 #在xhgui/config/config.default.php中,找到profiler.enable这里,按如下修改: #mongo //采样率 'profiler.enable' => function() { // url 中包含debug=1则百分百捕获 if(!empty($_GET['debug'])){ return true; } else { // 1%采样 return rand(1, 100) === 42; } }, //优化建议:可以给mongo数据表加上索引
//在需要的项目中的最开始,引入文件即可 require "/dir/external/header.php"; //操作项目,即可在xhgui平台中查看数据分析性能
The effect is as shown below
For more PHP related technical articles, please visit the PHP Tutorial column to learn!
The above is the detailed content of PHP performance analysis platform construction. For more information, please follow other related articles on the PHP Chinese website!