Laravel 4.2, Amazon ec2 Linux
PHP Fatal error:
Allowed memory size of 262144 bytes exhausted (tried to allocate 3072 bytes) in /var/www/html/vendor/composer/ClassLoader.php on line 78
Laravel 4.2, Amazon ec2 Linux
PHP Fatal error:
Allowed memory size of 262144 bytes exhausted (tried to allocate 3072 bytes) in /var/www/html/vendor/composer/ClassLoader.php on line 78
TL;DR You need to increase your memory_limit
setting in php.ini. You're barely letting your scripts use any memory at all.
The error message Allowed memory size of 262144...
means you have a memory_limit
setting of 256 kb. That is far too low. For most useful applications, you need at least a few MB. I would start with 8MB and see how it goes.
Change the memory_limit
setting. In theory, you can do this two ways: (1) edit php.ini or (2) use ini_set()
.
In practice, you cannot always use ini_set('memory_limit', value);
. For one thing, some extensions, like suhosin, prevent scripts from setting the memory_limit
in this way. For another, you have to be careful how you do it. For example, you proposed using ini_set('memory_limit', '1G');
. But the shorthand (K
, M
, G
) only works in php.ini, not in ini_set
. You would have to enter an actual number of bytes (e.g., 1073741824
). Also, 1G
is pretty excessive for most purposes; very, very few non-malicious PHP scripts need anything like that. Even pretty heavy frameworks like WordPress typically run well within 64 MB or so, even with lots of plugins loaded up.
Figure out which php.ini file you are using (it's not uncommon to have several floating around, depending on how you installed things). You can do this in two ways:
<?php phpinfo();
php -i | grep php.ini
. You should see a line that says something like Loaded Configuration File => /etc/php.ini
(the output may vary by system, of course).Edit the file you just found by changing the line that starts with memory_limit =
to something more appropriate, like
memory_limit = 8M
Feel free to bump that number up as needed, but I would recommend starting small (not 1G
) to prevent bringing your server to its knees accidentally.
One caveat: if this is a testing/development machine and you are running a debugger or profiler like xdebug, you may want to start much higher, and 1G
is not insane. But don't start with such a high number on a production machine; work your way up to it.