There is a bunch of PHP dump in OutOfMemory exception

I am currently debugging a script that constantly runs on OutOfMemory exceptions. It starts as a cronjob and usually works fine, but when the cronjob has not started for some time (for some reason), the script must handle many elements that are queued and will be thrown into the OutOfMemory exception.

Having studied the code, I could not find the problem. I believe one of the iterative function calls may be a memory leak, but I'm not sure which one and where. Is there a way to get PHP to drop the heap when an OutOfMemory exception is thrown? I could detect the problem from there (most likely).

+3
source share
6 answers

While I was not able to find the "dump dump by exception" parameter, I found get_defined_vars()that it is mainly a heap dump if called from a global scope. Using this, I was able to see that where in my memory hundreds (in fact thousands) of database reference lines hang. This was due to an unreleased mysql result resource somewhere in the infamous function that caused the leak. I found it and fixed it. Now it works well.

+5
source

, try-catch script, , catch. , - , . , , mermory .

EDIT. php debug-backtrace. . , , .

+1

, ----?

0

simpleXML . - , ... , , simpleXML , . , OOM:)

, PHP , , ~ 1 , PHP 100 :)

0

, " ", PHP. , . 100% - , , :

$memmap = array_map(function($var) { return strlen(serialize($var)); }, array_merge(get_defined_functions(), get_defined_vars())); arsort($memmap); var_dump($memmap);

, , , , .

0
source

I have never seen PHP provide a native mechanism for this, but there may be several other things:

Try: https://github.com/mcfunley/php-heap/blob/master/php-heap.py

You could also write an extension to achieve the same.

0
source

Source: https://habr.com/ru/post/1771297/


All Articles