Question

we have some rather large data-import scripts (Symfony "Commands") which are erroring out due to Monolog running out of memory (vendor\monolog\src\Monolog\Formatter\LineFormatter.php on line 58). we use Monolog in general, so would not like to disable it entirely.

Was it helpful?

Solution

I realise this is an old question, but when I ran into problems with a long-running, Monolog-using script generating out of memory errors, it turned out the problem was Monolog's 'fingers_crossed' handler buffering a ton of log messages.

I solved the problem by setting the 'buffer_size' variable for the Monolog handler in question. Something like this:

main:
    type:         fingers_crossed
    action_level: info
    buffer_size:  200
    handler:      nested

Edit: As pointed out by Sergio in the comments, buffer_size sets: 'How many entries should be buffered at most, beyond that the oldest items are removed from the buffer'.

OTHER TIPS

Since in prod environment you have problems with Doctrine I don't think focusing on logger will improve your situation. However, you could try popping log handlers off the stack with multiple calls to $logger->popHandler(). Might be that log messages are stacked and therefore you run out of memory.

More likely you have issues with doctrine though.

I'd try using XHProf or XDebug to see where's the actual issue. Just because your script fails at one point doesn't mean it's the cause of the problem (actual memory leak might be somewhere else).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top