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).
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.
get_defined_vars()
, try-catch script, , catch. , - , . , , mermory .
EDIT. php debug-backtrace. . , , .
, ----?
simpleXML . - , ... , , simpleXML , . , OOM:)
, PHP , , ~ 1 , PHP 100 :)
, " ", PHP. , . 100% - , , :
$memmap = array_map(function($var) { return strlen(serialize($var)); }, array_merge(get_defined_functions(), get_defined_vars())); arsort($memmap); var_dump($memmap);
, , , , .
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.
Source: https://habr.com/ru/post/1771297/More articles:Do I need to use Google Account Authentication instead of Spring Authentication to avoid Firesheep cookie-sniffing attacks? - javaКак преобразовать URL-адрес html-страницы в pdf в java с помощью iText и летающей тарелки? - javaSharePoint Document or Download / View Event Handler? - event-handlingexception with no 'to_query' method - ruby | fooobar.comВыполните некоторое очистку, когда окно формы закрыто - user-interfaceIs there a shorter way to define a list, for example. 100 new arrays? - javascriptForeach, специальная обработка каждого n-го элемента (нечетное, например, например) - phpTurn boost :: tuples :: cons <...> back into the corresponding boost :: tuple <...> - c ++Передача команд между двумя компьютерами через Интернет - javapostgres-start process under administrator account - windowsAll Articles