How to know the URL which caused PHP to go OOM
I am debugging a problem I found while reading the PHP error logs:
[14-Mar-2011 09:53:31] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 24 bytes) in XXX.php on line 77
The problem is that code it points to is very generic code, used by most pages, so I'm having an extremely hard time trying to reproduce it. I really need the URL that triggered the error.
What can I do? This is what I tried:
- To find the problem from the file/line the error point开发者_开发百科s to.
- Examined the error log to see if it's always the same amount of bytes (it's not), the same line (it's not), the same file (it is 99% of the time).
- Checked how common this error is: very common (~1 per second)
- Grepped the access log for "14-Mar-2011 09:53:31", but we get TONS of hits per second and going through all of them is very unfeasible.
You should use the set_error_handler();
With that function you can create your own error handler saving the php script, line and the REQUEST_URI that generated it.
It was the first think i developed for a framework because it's very important to have a better error handler
One caveat, if you are working in a multi-platform enviroment (linux and windows for example), there is a possibility that the error is referring to the wrong line and causing confusion if line breaking is set wrong when saving the file for the target system. Happened to us many a time and caused a lot of grief. Fixing that little detail usually made isolating the culprit a breeze. I'm not saying that this is the case, but it's worth checking.
As of php 5.2 you can see this http://www.php.net/manual/en/function.set-error-handler.php#99193
精彩评论