Skip to content

Commit

Permalink
Explain a way to capture memory_limit violations
Browse files Browse the repository at this point in the history
  • Loading branch information
sj-i committed Nov 23, 2023
1 parent 6fa396b commit 6ae0154
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/memory-profiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@ $ cat memory_analized.json | jq 'path(..|objects|select(."#reference_node_id"==3
## Capturing the memory_limit violation
If you can modify the target script, you can also capture the memory_limit violation via `register_shutdown_function()`, like this.
```php
<?php
ini_set('memory_limit', '2M');
register_shutdown_function(
function (): void {
$error = error_get_last();
if (is_null($error)) {
return;
}
if (strpos($error['message'], 'Allowed memory size of') !== 0) {
return;
}
$pid = getmypid();
system("sudo reli i:m -p {$pid} --stop-process=0 >dump.json");
}
);
$var = [];
for ($i = 0; $i < 1000000; $i++) {
$var[] = array_fill(0, 0x10000, 0);
}
```
## More detailed explanation of the output
### The "summary" field
```bash
Expand Down

0 comments on commit 6ae0154

Please sign in to comment.