You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function generates a dump of the PHP memory in a JSON format. This dump can be later analyzed by the provided analyzers.
58
55
59
56
This functions takes a stream handle as a parameter. It allows you to specify a file (ex `fopen('/tmp/file.txt', 'w')`, as well as to use standard output with the `php://stdout` stream.
60
57
61
-
## Information gathered
62
-
Each memory item (string, boolean, objects, array, etc...) is dumped with the following information:
63
-
- in-memory address
64
-
- type (object, array, int, string, ...)
65
-
- class (only for objects)
66
-
- object handle (only for objects)
67
-
- self size (without the size of the linked objects)
68
-
- is_root (tells if the item is directly linked to a declared variable in the PHP program)
69
-
- symbol name (name of the variable name in the PHP program, if the item is linked to a variable)
70
-
- execution frame (name of the method where the variable has been declared)
71
-
- children: list of linked items with the key name in case of array or property name if object, associated to their address in memory
Decreasing performances is usually the most visible part. As memory leak saturates the garbage collector buffer, it runs far more often, without being able to free any memory. This leads to a high CPU usage of the process, with a lot of time spent in the garbage collector instead of your code (garbage collector doesn't run in parallel with the user code in PHP, it has to interrupt it).
81
+
## Querying the memory dump to find specific objects
82
+
```bash
83
+
$ bin/analyzer query [options] [--] <dump-file>
86
84
87
-
See https://speakerdeck.com/bitone/hunting-down-memory-leaks-with-php-meminfo for a more detailed insight on how memory leak can occur.
85
+
Arguments:
86
+
dump-file PHP Meminfo Dump File in JSON format
88
87
89
-
Memory Leak Hunting Process
90
-
----------------------------
91
-
## Overview
92
-
1. dump memory state with `meminfo_info_dump`
93
-
2. use the *summary* command of the analyzer to display the item type that is the most present in memory. It's even better to use the summary to display the evolution of objects in memory in order, as the evolution will show where the memory leak really is
94
-
3. use the *query* command of the analyzer to find one item from the class that is leaking
95
-
4. use the *ref-path* command analyzer to find out the references that still hold this object in memory
88
+
Options:
89
+
-f, --filters=FILTERS Filter on an attribute. Operators: =, ~. Example: class~User (multiple values allowed)
90
+
-l, --limit=LIMIT Number of results limit (default 10).
91
+
-v Increase the verbosity
92
+
```
96
93
97
-
## Object Leaks
98
-
On object oriented programming, a memory leak usually consists of *objects* leak.
The analyzer is available from the `analyzer/` directory. It will be invoked with:
104
-
```bash
105
-
$ bin/analyzer
106
117
```
107
118
108
-
#### Querying a memory dump
109
-
The `query` command on the analyzer allows you to filter out some items from a memory dump. The `-f` option can be used several times, effectively *anding* the filters. The supported operators are exact match `=` and regexp match `~`.
119
+
## Displaying the reference path
120
+
The reference path is the path between a specific item in memory (identified by it's
121
+
pointer address) and all the intermediary items up to the one item that is attached
122
+
to a variable still alive in the program.
110
123
111
-
The `-v`option display all the information of the items found.
124
+
This path shows who are the items responsible for the memory leak of the specific item
125
+
provided.
112
126
113
-
##### Examples
114
-
- finding array that are not directly linked to a variable
#### Finding out why an object has not been removed from memory
124
-
When you are tracking down a memory leak, it's very interesting to understand why an object is still in memory.
130
+
Arguments:
131
+
item-id Item Id in 0xaaaaaaaa format
132
+
dump-file PHP Meminfo Dump File in JSON format
125
133
126
-
The analyzer provides the `ref-path` command that load the memory dump as a graph in memory and findout all paths linking an item to a root (a variable define in an execution frame).
134
+
Options:
135
+
-v Increase the verbosity
136
+
```
127
137
128
-
Without the `-v` option, the output will contains only item memory address and key/property name. Adding the `-v` option will display all the information of the linked items.
0 commit comments