3

I started to receive this error in my Laravel log Allowed memory size of 536870912 bytes exhausted (tried to allocate 227371200 bytes)

Is there is any way to get more information on what script / file being attempted to manipulate? I looked for similar size file on server and I couldn't find anything.

My first call was that maybe it's some log file that got too big.

Upping memory limit to 2GB solved the problem partially, but my worry is that this quick fix is not solving actual issue as I have no clue what file is being attempted to change or why script needs so much memory.

From what I can tell it happens when one of my /api function being called.

If it was infinite loop I assume upping the limit would not help.

    "class": "Symfony\\Component\\Debug\\Exception\\FatalErrorException",
    "message": "Allowed memory size of 536870912 bytes exhausted (tried to allocate 227371200 bytes)",
    "code": 1,
    "file": "\/vendor\/league\/flysystem\/src\/Util\/MimeType.php:188"
}```
Sam Axe
  • 437
  • 1
  • 8
  • 25
  • Am assuming this is something related to file upload, it would be great to have the full call stack of the log file, the information you provided so far isn't helpful – Salim Djerbouh Aug 26 '19 at 16:39
  • @CaddyDZ that's the problem, this is all I get in error log, I want to get more information, but it's all that comes through – Sam Axe Aug 26 '19 at 16:47

2 Answers2

2

You can handle files as streams to prevent memory issues with large files.

See Storage::putFile() here or use PHPs fopen() to get a stream handle you can pass to Laravels storage methods.

Olivenbaum
  • 971
  • 1
  • 6
  • 17
  • the main problem is that I can't find out what file is being attempted to manipulate that requires so much memory. – Sam Axe Aug 26 '19 at 19:03
  • 2
    Then you have to check every step your application takes when accessing a route that triggers this error. Somewhere [MimeType](https://github.com/thephpleague/flysystem/blob/master/src/Util/MimeType.php#L188) tries to guess the mime-type of a very large file... – Olivenbaum Aug 26 '19 at 19:08
0

This looks like a known bug in PHP - https://bugs.php.net/bug.php?id=78987 which is caused by an upstream bug in libmagic - https://bugs.astron.com/view.php?id=234

fisharebest
  • 1,300
  • 10
  • 16