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

2 min read

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.

Tags : PHP

Related Post

How to get the php.ini file path in PHP?
How to Format numbers to nearest thousands in php
How to generate random Hex color in PHP
How to increase maximum execution time in PHP
Maksud

Maksud

I am a thinker, not a talker.