Open jdecool opened 2 years ago
I made an attempt at implementing this feature a while back, with some success. However, I was playing around with learning c and PHP extensions and I went a bit off the rails, so my fork is probably not a suitable contribution to this project.
Good work @tortis
I think you can try to add this feature in the official project. I think @BitOne will help you to improve your code if needed :)
I think the changes required to add this feature alone wouldn't be too bad. One problem that I ran into when testing it, was that it was very easy to trigger a secondary OOM error while performing the memory dump triggered by the original OOM error.
I attempted to mitigate this problem by converting the "visited items" hash set to not use a PHP (zend) hash which was causing more PHP allocations that can trigger the PHP runtime to OOM again. This might have not been necessary at all, since I think you could just turn off (or increase) the zend memory limit when the first OOM happens. I don't know for sure if that works.
For the same reason, I also converted the recursive traversal to iterative with a stack.
Most of the other changes on my fork were just random stuff where I was playing with the code and doing light refactoring while trying to understand how it works.
@BitOne Is this a feature you'd be interested in adding? I could try an implementation of it with out all the other changes. Or if you'd rather handle it yourself feel free to use any of the work on my branch.
Hello!
That would be a wonderful feature! I remember I discussed it some years ago with Julien Pauli who at that time was release manager of PHP.
It's something that exists on the Java Virtual Machine, and it is indeed extremely useful.
If that's okay for you @tortis , can you do a PR here?
I sometimes use the php-memory-profiler with your library to debug memory usage of my projects.
This extension has a nice feature that allows to automatically dump a memory profile when the process crash because of a memory limit.
It could be cool to have this feature for this extension.