PHP Fatal Error memory flags

by Moises Jafet — on  ,  ,  , 
Tiempo de Lectura aprox.: 3 Minutos, 1 Segundo

Been PHP a tool for Web Apps for the Browser, for the most part, a well configured Production Web Server serves you a white screen if a Fatal Error occurs. It takes some experience to force the Parser to print out on screen the error message; but sometimes there's no error message at all as in the case of memory leaking of a long, looping, multi-table joining, file crawler script or the App just runs out of RAM memory. All you have as evidence that something went wrong is a white screen -of death-.

You can tell, in those cases, observing the spitted HTML as source code on the Browser, that the flushing has stopped at some point before the HTML document is complete, the reason why the Browser shows a white screen without flaring a Fatal Error.

Surely you have a standardized deployment workflow with your Development/Staging/Production separated environments, but nor the Development or Staging environments will have access to the Production data or at least not to the big databases and file repositories as the Production one because the error appears when a user uploads or adds in the next data item that passed the threshold for the memory breaking point, which makes sense that you haven't dealt with the issue before and comfortably.

There are bad days too, of course…

So, you will have to turn on error reporting in all its glory on Production, because in my own experience, you will never get logged on file memory exhaustion events, because the whole stuff got out of breath even for filing the complaint out with the logger routine.

And, then you managed to get:

PHP: Fatal Error: Allowed Memory Size of 67108864 Bytes Exhausted

But, what to get in clear about that message?

Talking Human

Here a list of equivalences:

  • PHP: Fatal Error: Allowed Memory Size of 8388608 Bytes Exhausted = 8 MB
  • PHP: Fatal Error: Allowed Memory Size of 16777216 Bytes Exhausted = 16 MB
  • PHP: Fatal Error: Allowed Memory Size of 33554432 Bytes Exhausted = 32 MB
  • PHP: Fatal Error: Allowed Memory Size of 67108864 Bytes Exhausted = 64 MB
  • PHP: Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted = 128 MB
  • PHP: Fatal Error: Allowed Memory Size of 268435456 Bytes Exhausted = 256 MB
  • PHP: Fatal Error: Allowed Memory Size of 536870912 Bytes Exhausted = 512 MB
  • PHP: Fatal Error: Allowed Memory Size of 1073741824 Bytes Exhausted = 1 GB

Finding the culprit

  • Check out your loaded php.ini, A good starting point. Try increasing the memory value there.
  • Check out your Apache, Ngnix or ISS Virtualhost parameters. If you are operating from a commercial Webhosting, some may alter the environment at that layer.
  • Check out for any .htaccess files, because some developers leftovers…

But,

Sometimes your environment memory limit is set at script level, probably because you are using third party libraries or you are working on a CMS app and the module vendor specifically needs to generate caching or build complex dashlets, so whatever 1, 2, 3 said is irrelevant. Of course, whoever sets the memory limit, uses a human version of the numbers, but your message is in machine format.

A good way to find the culprit script is just to grep (or any Regular Expressions deep search tool you may have available) for the number in human format.

For example if PHP errors out claiming:


PHP: Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted

Then,


grep -r 128M /wherever/your/sourcecode/is 

Edit the script and you should be fine; but, don't abuse of upper memory limits, which is a totally different topic.

Debugging is fun, sometimes…

Blog Comments powered by Disqus.

Moisés Jafet Cornelio-Vargas

About Moisés

Profile picture

Physicists, award-winning technologist, parallel entrepreneur, consultant and proud father born in the Dominican Republic.
Interested in HPC, Deep Learning, Semantic Web, Internet Global High Scalability Apps, InfoSec, eLearning, General Aviation, Formula 1, Classical Music, Jazz, Sailing and Chess.
Founder of pluio.com and hospedio.com.
Author of the Sci-fi upcoming novel Breedpeace and co-author in dozens of publications.
Co-founder of MunicipiosAlDia.com, Jalalio Media Consultants and a number of other start-ups.
Former professor and Key-note speaker in conferences and congresses all across the Americas and Europe.
Proud member of the Microchip No.1 flying towards Interestellar space on board NASA's Stardust Mission, as well as member of Fundación Municipios al Día, Fundación Loyola, Fundación Ciencias de la Documentación and a number of other non-for profit, professional organizations, Open Source projects and Chess communities around the world.
All opinions here are his own's and in no way associated with his business interests or collaborations with third-parties.