monxas monxas - 1 year ago 99
PHP Question

Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes)

I was going crazy with this.

I got the next message:

Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes)


Check phpinfo(), got the right php.ini route and edit it.
Change memory_limit to

memory_limit = 128M

Make sure the value memory_limit changes con phpinfo() with the result:

memory_limit 128MB 128MB

Check .htaccess and added (not needed)

php_value memory_limit 128M

And also to change it via php like so (before error line):


It says everywhere that memory is set to 128M, but still get that error?

The error is in Swift library (library for sending emails), in abstractSmtpTransport.php, so it's not my code int's suposed to work.

Any ideas???

Edit: Yes, the previous was done restarting apache.

@patrick, added that but nothing was echoed

Tryed with lower value, 28M int every file, restarted apache, same error (phpinfo showed new value)

tried with -1, restarting, and same error.

EDIT 3: isn't it weird that allowed memory is bigger than allocated memory? (despite the fact that allowed memory size is way below real allowed memory asigned)

Answer Source

I see my problem is a little bit different from yours, but I'll post this answer in case it helps someone else. I was using MB as shorthand instead of M when defining my memory_limit, and php was silently ignoring it. I changed it to an integer (in bytes) and the problem was solved.

My php.ini changed as follows: memory_limit = 512MB to memory_limit = 536870912. This fixed my problem. Hope it helps with someone else's! You can read up on php's shorthand here.

Good luck!


As Yaodong points out, you can just as easily use the correct shorthand, "M", instead of using byte values. I changed mine to byte values for debugging purposes and then didn't bother to change it back.