git clone https://github.com/longxinH/xhprof.git ./xhprof
cd xhprof/extension/
/path/to/php7/phpize
./configure --with-php-config=/path/to/php7/bin/php-config --enalbe-xhprof
make && sudo make install
[xhprof]
extension=xhprof.so;
xhprof.output_dir=/var/tmp/xhprof
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
// 要检查性能的代码
$xhprof_data = xhprof_disable();
include_once '/path/to/xhprof/xhprof_lib/utils/xhprof_lib.php';
include_once '/path/to/xhprof/xhprof_lib/utils/xhprof_runs.php';
$xhprof_runs = new \XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, 'your_project');
require_once '/path/to/xhprof/start.php';
// 要检查性能的代码
require_once '/path/to/xhprof/end.php';
require_once '/path/to/xhprof/start.php';
register_shutdown_function(function() {
$xhprof_data = xhprof_disable();
if (function_exists('fastcgi_finish_request')){
fastcgi_finish_request();
}
include_once "/path/to/xhprof/xhprof_lib/utils/xhprof_lib.php";
include_once "/path/to/xhprof/xhprof_lib/utils/xhprof_runs.php";
$xhprof_runs = new XHProfRuns_Default();
$run_id = $xhprof_runs->save_run($xhprof_data, 'your_project');
});
php_value[auto_prepend_file] = /path/to/xhprof/start.php
php_value[auto_append_file] = /path/to/xhprof/end.php
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "auto_prepend_file=/path/to/xhprof/xhprof.php";
include fastcgi_params;
}
auto_prepend_file = /path/to/xhprof/xhprof.php
server {
listen 80;
root /path/to/xhprof/xhprof_html;
server_name your_host;
location = / {
index index.php;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
cd /path/to/xhprof/xhprof_html
php -S 127.0.0.1:9000