[GH-ISSUE #91] Buffer handler not working as expected on php 5.3.10 #33

Closed
opened 2026-03-04 02:11:32 +03:00 by kerem · 5 comments
Owner

Originally created by @Shreef on GitHub (Jun 14, 2012).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/91

The Buffer handler depends on the __destruct() method to push the buffered records to the sub-handler. looks like this doesn't always work on PHP 5.3.10 as destructors don't run on shutdowns caused by fatal errors.

the solution would require adding this line to the constructor of the AbstractHandler

register_shutdown_function(array($this, '__destruct'));
Originally created by @Shreef on GitHub (Jun 14, 2012). Original GitHub issue: https://github.com/Seldaek/monolog/issues/91 The Buffer handler depends on the `__destruct()` method to push the buffered records to the sub-handler. looks like this doesn't always work on PHP 5.3.10 as destructors don't run on shutdowns caused by fatal errors. the solution would require adding this line to the constructor of the `AbstractHandler` ``` php register_shutdown_function(array($this, '__destruct')); ```
kerem closed this issue 2026-03-04 02:11:32 +03:00
Author
Owner

@Seldaek commented on GitHub (Jun 14, 2012):

It's not a bad idea, but I'm not sure if that would work very well, because then it keeps a reference to the object, which means it won't be destructed until the very end, and that means if it has any dependencies to be able to send the logs, it might just fail. I'd feel more comfortable adding that only to the buffer handler and not to the abstract one.

<!-- gh-comment-id:6326453 --> @Seldaek commented on GitHub (Jun 14, 2012): It's not a bad idea, but I'm not sure if that would work very well, because then it keeps a reference to the object, which means it won't be destructed until the very end, and that means if it has any dependencies to be able to send the logs, it might just fail. I'd feel more comfortable adding that only to the buffer handler and not to the abstract one.
Author
Owner

@Shreef commented on GitHub (Jun 14, 2012):

@Seldaek
Ok, makes sense

<!-- gh-comment-id:6326529 --> @Shreef commented on GitHub (Jun 14, 2012): @Seldaek Ok, makes sense
Author
Owner

@stof commented on GitHub (Jun 14, 2012):

I would also register the close method directly instead of the magic function

<!-- gh-comment-id:6326545 --> @stof commented on GitHub (Jun 14, 2012): I would also register the close method directly instead of the magic function
Author
Owner

@Shreef commented on GitHub (Jun 14, 2012):

Cool. I hope you can implement the solution and close the issue. if you need me to send a pull request or something, just let me know.

<!-- gh-comment-id:6326882 --> @Shreef commented on GitHub (Jun 14, 2012): Cool. I hope you can implement the solution and close the issue. if you need me to send a pull request or something, just let me know.
Author
Owner

@Seldaek commented on GitHub (Jun 14, 2012):

@Shreef if you don't mind sending a PR, that'd be great.

<!-- gh-comment-id:6326893 --> @Seldaek commented on GitHub (Jun 14, 2012): @Shreef if you don't mind sending a PR, that'd be great.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#33
No description provided.