How to Increase PHP Memory Using ini_set()
Sometimes there might be a need to increase the allocated memory for PHP to run something that needs more power. Normally it’s a large file that is simply just being opened in memory.
You might be receiving this error:
Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted.
There is a super simple way to increase allocated memory for a single script:
<?php ini_set('memory_limit','256M'); //add the rest of your PHP script here. ?>
This will allocate 256M to your script. This should be placed at the top of the script next to the opening <?php tag. Careful how much you allocate, giving PHP to much memory can momentarily cause system instability. For this reason you’ll find it might be disabled on shared hosting.