[GH-ISSUE #1795] SyslogUdpHandler autoclose option #761

Closed
opened 2026-03-04 02:17:45 +03:00 by kerem · 3 comments
Owner

Originally created by @boesing on GitHub (Mar 2, 2023).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1795

Hey there,

we do have some longrunning processes using pcntl_fork which do log stuff via SyslogUdpHandler to our syslog.
Due to the fact that it is a longrunning process, the UDP socket is never closed and therefore stays open until the process is restarted.
I wonder if it would make sense to have an option available in the SyslogUdpHandler which allows projects to configure some socketAutoClose option so that the socket is being closed after message is being sent.

I am open for other suggestions as well (i.e. some CloseAfterProcessHandler which decorates another processor).
Thanks for your time.

Max

Originally created by @boesing on GitHub (Mar 2, 2023). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1795 Hey there, we do have some longrunning processes using `pcntl_fork` which do log stuff via `SyslogUdpHandler` to our syslog. Due to the fact that it is a longrunning process, the UDP socket is never closed and therefore stays open until the process is restarted. I wonder if it would make sense to have an option available in the `SyslogUdpHandler` which allows projects to configure some `socketAutoClose` option so that the socket is being closed after message is being sent. I am open for other suggestions as well (i.e. some `CloseAfterProcessHandler` which decorates another processor). Thanks for your time. Max
kerem 2026-03-04 02:17:45 +03:00
Author
Owner

@Seldaek commented on GitHub (Mar 10, 2023):

If you're using Monolog 3, you can call $logger->close() as well as $logger->reset() in between "jobs" or whatever you have as a good point to do this where it makes sense, that would then be reopened whenever something needs to be written again.

github.com/Seldaek/monolog@d3d495b742/src/Monolog/Logger.php (L401-L416)

<!-- gh-comment-id:1463793472 --> @Seldaek commented on GitHub (Mar 10, 2023): If you're using Monolog 3, you can call $logger->close() as well as $logger->reset() in between "jobs" or whatever you have as a good point to do this where it makes sense, that would then be reopened whenever something needs to be written again. https://github.com/Seldaek/monolog/blob/d3d495b742cacf9c0af87867bf87dab2fc591e68/src/Monolog/Logger.php#L401-L416
Author
Owner

@boesing commented on GitHub (Mar 10, 2023):

I do not have a strong need in closing all handlers. Some do not need to be closed as they do not keep ports open, that seems only being the case for the udp socket here 🤔

I have no handler doing http requests but I dont think that curl keeps TCP ports open which were used to send HTTP requests?

<!-- gh-comment-id:1464009333 --> @boesing commented on GitHub (Mar 10, 2023): I do not have a strong need in closing all handlers. Some do not need to be closed as they do not keep ports open, that seems only being the case for the udp socket here 🤔 I have no handler doing http requests but I dont think that curl keeps TCP ports open which were used to send HTTP requests?
Author
Owner

@Seldaek commented on GitHub (Mar 10, 2023):

You can also close the UDP handler directly of course, if that's more appropriate, but IMO closing/resetting everything between jobs in long running worker processes is a good approach.

<!-- gh-comment-id:1464016527 --> @Seldaek commented on GitHub (Mar 10, 2023): You can also close the UDP handler directly of course, if that's more appropriate, but IMO closing/resetting everything between jobs in long running worker processes is a good approach.
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#761
No description provided.