Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
# xhprof for PHP7 and PHP8
2
[![Build Status](https://travis-ci.com/longxinH/xhprof.svg?branch=master)](https://app.travis-ci.com/github/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)
3
 
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.
5
 
6
This version supports PHP7 and PHP8
7
 
8
# PHP Version
9
- 7.2
10
- 7.3
11
- 7.4
12
- 8.0
13
- 8.1
14
- 8.2
15
 
16
# Installation
17
```
18
git clone https://github.com/longxinH/xhprof.git ./xhprof
19
cd xhprof/extension/
20
/path/to/php7/bin/phpize
21
./configure --with-php-config=/path/to/php7/bin/php-config
22
make && sudo make install
23
```
24
 
25
#### configuration add to your php.ini
26
```
27
[xhprof]
28
extension = xhprof.so
29
xhprof.output_dir = /tmp/xhprof
30
```
31
 
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|
39
 
40
# Turn on extra collection
41
#### php.ini adds xhprof.collect_additional_info
42
```sh
43
xhprof.collect_additional_info = 1
44
````
45
# Options
46
```php
47
xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
48
```
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
52
 
53
Example
54
```php
55
<?php
56
 
57
array(
58
    "main()" => array(
59
        "wt" => 237,
60
        "ct" => 1,
61
        "cpu" => 100,
62
    )
63
)
64
```
65
 
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
71
 
72
### PDO::exec
73
### PDO::query
74
### mysqli_query
75
```php
76
$mysqli = new mysqli("localhost", "my_user", "my_password", "user");
77
$result = $mysqli->query("SELECT * FROM user LIMIT 10");
78
```
79
##### Output data
80
```
81
mysqli::query#SELECT * FROM user LIMIT 10
82
```
83
 
84
### PDO::prepare
85
Convert preprocessing placeholders for actual parameters, more intuitive analytic performance (does not change the zend execution process)
86
```php
87
$_sth = $db->prepare("SELECT * FROM user where userid = :id and username = :name");
88
$_sth->execute([':id' => '1', ':name' => 'admin']);
89
$data1 = $_sth->fetch();
90
 
91
$_sth = $db->prepare("SELECT * FROM user where userid = ?");
92
$_sth->execute([1]);
93
$data2 = $_sth->fetch();
94
```
95
##### Output data
96
```
97
PDOStatement::execute#SELECT * FROM user where userid = 1 and username = admin
98
PDOStatement::execute#SELECT * FROM user where userid = 1
99
```
100
 
101
### Curl
102
```php
103
$ch = curl_init();
104
curl_setopt($ch, CURLOPT_URL, "http://www.baidu.com");
105
$output = curl_exec($ch);
106
curl_close($ch);
107
```
108
##### Output data
109
```
110
curl_exec#http://www.baidu.com
111
```
112
 
113
## PECL Repository
114
[![pecl](resource/pecl.png)](https://pecl.php.net/package/xhprof)