How to Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted

Avatar
C

Callum Davies

Senior Backend Engineer••
8660Views
5mRead
0Reactions

In this article, I will share how to fix the below error in any PHP project. The reason for this error is that your server configuration has a very low memory limit.

 

This is a common issue for PHP developers. Common issues - 

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

 

Solution:

1. Increate memory size via ini_set

<?php

ini_set('memory_limit', '1024M'); // or you could use 1G

 

2. manually edit php.ini file, change default memory_limit

memory_limit = 1024M

 

You can check your memory limit

<?php
echo ini_get(‘memory_limit’).PHP_EOL

 

I hope, it will fix your problem.

Connect with KoderSolution 🚀

Master modern software engineering, scalable architectures, and advanced backend systems.

What's your setup?What's your production setup for this scenario? Have you encountered similar architectural bottlenecks or edge-case gotchas?
Callum Davies
C
Written by•Senior Backend Engineer

Callum Davies

PHP & Laravel practitioner since v5.4. Big believer in thin controllers, explicit return types, and boring modular architecture that doesn't page you on weekends.

React to this article

Recommended Articles

View all articles