2 [![Build Status](https://travis-ci.com/longxinH/xhprof.svg?branch=master)](https://travis-ci.com/longxinH/xhprof) [![Build status](https://ci.appveyor.com/api/projects/status/dornfeel5yutaxte/branch/master?svg=true)](https://ci.appveyor.com/project/longxinH/xhprof/branch/master)
4 XHProf is a function-level hierarchical profiler for PHP and has a simple HTML based navigational interface. The raw data collection component is implemented in C (as a PHP extension). The reporting/UI layer is all in PHP. It is capable of reporting function-level inclusive and exclusive wall times, memory usage, CPU times and number of calls for each function. Additionally, it supports ability to compare two runs (hierarchical DIFF reports), or aggregate results from multiple runs.
6 This version supports PHP7
18 git clone https://github.com/longxinH/xhprof.git ./xhprof
20 /path/to/php7/bin/phpize
21 ./configure --with-php-config=/path/to/php7/bin/php-config
22 make && sudo make install
25 #### configuration add to your php.ini
29 xhprof.output_dir = /tmp/xhprof
32 ### php.ini configuration
33 | Options | Defaults | Version | Explain |
34 | --------------- |:-------------:|:-------------:|:---------|
35 |xhprof.output_dir | "" | All |Output directory|
36 |xhprof.sampling_interval | 100000 | >= v2.* | Sampling interval to be used by the sampling profiler, in microseconds|
37 |xhprof.sampling_depth | INT_MAX | >= v2.* | Depth to trace call-chain by the sampling profiler|
38 |xhprof.collect_additional_info | 0 | >= v2.1 | Collect mysql_query, curl_exec internal info. The default is 0. Open value is 1|
40 # Turn on extra collection
41 #### php.ini adds xhprof.collect_additional_info
43 xhprof.collect_additional_info = 1
47 xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
49 - `XHPROF_FLAGS_NO_BUILTINS` do not profile builtins
50 - `XHPROF_FLAGS_CPU` gather CPU times for funcs
51 - `XHPROF_FLAGS_MEMORY` gather memory usage for funcs
66 - `wt` The execution time of the function method is time consuming
67 - `ct` The number of times the function was called
68 - `cpu` The CPU time consumed by the function method execution
69 - `mu` Memory used by function methods. The call is zend_memory_usage to get the memory usage
70 - `pmu` Peak memory used by the function method. The call is zend_memory_peak_usage to get the memory
76 $mysqli = new mysqli("localhost", "my_user", "my_password", "user");
77 $result = $mysqli->query("SELECT * FROM user LIMIT 10");
81 mysqli::query#SELECT * FROM user LIMIT 10
85 Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process)
87 $_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name");
88 $_sth->execute([':id' => '1', ':name' => 'admin']);
89 $data1 = $_sth->fetch();
91 $_sth = $db->prepare("SELECT * FROM user where userid = ?");
93 $data2 = $_sth->fetch();
97 PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin
98 PDOStatement::execute#SELECT * FROM user where userid = 1
104 curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com");
105 $output = curl_exec($ch);
110 curl_exec#http://www.baidu.com
114 [![pecl](resource/pecl.png)](https://pecl.php.net/package/xhprof)