Home > Backend Development > PHP Tutorial > PHP performance analysis tool xhprof

PHP performance analysis tool xhprof

藏色散人
Release: 2023-04-08 07:00:02
forward
3519 people have browsed it

php Install xhprof extension (compatible with php5 and 7)

git clone git@github.com:longxinH/xhprof.git
cd xhprof 
/usr/local/php7/bin/phpize 
./configure --with-php-config=/usr/local/php7/bin/php-config 
make 
sudo make install
Copy after login

The extension is compiled, confirm it

ls /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/xhprof.so
Copy after login

Put the prepend file in /tmp/xhprof.prepend .php under

vi /usr/local/php7/lib/php.ini
[xhprof]
extension=xhprof.so
auto_prepend_file ="/tmp/xhprof.prepend.php";
Copy after login

Restart apache

ps: prepend file xhprof.prepend.php

<?php
xhprof_sample_enable();
define(&#39;XHPROF_START_TIME&#39;, microtime(true));
register_shutdown_function(function () {
    $xhprof_time = microtime(true) - XHPROF_START_TIME;
    $xhprof_data = xhprof_sample_disable();
    if ($xhprof_time > 2 && !empty($xhprof_data)) {
        array_unshift($xhprof_data, http_build_query($_REQUEST));
        $xhprof_file = &#39;/tmp/xhprof/&#39; . date(&#39;YmdHis0000&#39;) . uniqid() . &#39;.&#39;
            . str_replace(&#39;.&#39;, &#39;_&#39;, strtolower((isset($_SERVER[&#39;HTTP_HOST&#39;]) ? $_SERVER[&#39;HTTP_HOST&#39;] : &#39;NOHOST&#39;)
            . &#39;-&#39; . (isset($_SERVER[&#39;REQUEST_METHOD&#39;]) ? $_SERVER[&#39;REQUEST_METHOD&#39;] : &#39;NOMETHOD&#39;)))
            . &#39;.xhprof&#39;;
        file_put_contents($xhprof_file, serialize($xhprof_data));
    }
});
Copy after login

The above is the detailed content of PHP performance analysis tool xhprof. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:lukachen.com
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template