Allowed Memory Size Exhausted - but allocation number is below allowed memory size

I am getting the error “PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4096 bytes)”.

Is allocation number the number of bytes that exceeded the max memory size? Or is it trying to allocate 4096 bytes and failing despite the limit being higher?

Try adding this script and it should give you more information:

<?php 
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', 'true');

echo ini_get('memory_limit');

// phpinfo();

ini_set('memory_limit', '128M');
echo '<br>' .ini_get('memory_limit');

Edit:

I have memory_limit set at 128M

Thanks, but I know the memory limit (it is 64mb) and error reporting is already at the max. I need to know how to interpret the error before trying to fix it. Is it failing to allocate 4096 bytes because it exceeded the memory limit already (it is trying to use 64mb + 4096 bytes), or it failing to allocate 4096 bytes even though 4096 is lower than the memory limit of 64mb? The error message is ambiguous to me.

The error message means that there was insufficient memory for the next packet of 4K.

3 Likes

Try increasing the ini_set(…); size by a substantial amount and check to ensure the value has been set then use the following to see how much memory is being used:

https://www.php.net/manual/en/function.memory-get-usage.php

Yes, so for example the current memory usage may be 64M - 2K, so storing 4K won’t fit - it would exceed the memory limit by 2K.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.