How to Resolve Memory Shortage Issue When EC2, Laravel, and Queue Processes Stop
Thank you for your continued support.
This article contains advertisements that help fund our operations.
Table Of Contents
Notes on what to do when there was not enough memory when trying to perform heavy tasks with Laravel Queue.
Error Message
Allowed memory size of 134217728 bytes exhausted (tried to allocate 1638400 bytes)Environment
EC2
Laravel
supervisorIn this case, it occurred when running heavy tasks asynchronously using Queue.
Conclusion
It is possible that you exceeded the amount of memory set in the php.ini configuration file.
This error can occur not only with queues but also with actions like composer install.
Solution
Find where php.ini is located
php --iniBy running this command.
In my case, I installed php7.4, so I can find it by running:
php74 --iniand it will show:
Loaded Configuration File: /etc/opt/remi/php74/php.iniThis is the location of php.ini.
When you don't know the PHP version
You can use the function phpinfo() to check various information.
If it's a development or test environment, this is the fastest way to find out (never do this in a production environment).
Write the following in web.php
Route::get('aaaaaaa', function () {
dd(phpinfo());
return redirect()->route('login');
});Accessing http://????/aaaaaaa will show you the information.
Look for the location of the php.ini file in the information.
In this case, it was found in:
/etc/opt/remi/php74/php.iniEdit the file
Open the file location you found earlier with vim.
sudo vim /etc/opt/remi/php74/php.iniYou'll see:
memory_limit = 128MChange it to:
memory_limit = 256MIn vim, you can search with:
/memoryAfter editing, save with:
/wq⇨Basic Vim Commands for EC2 and other uses
Restart Apache
One-line command to restart Apache.
sudo systemctl restart httpdDon't forget to restart supervisor
Memory shortage issues in queues won't be resolved until you restart them (easy to forget).
supervisorctl restart allThe queue has been restarted.
Summary
These are the steps to resolve memory shortage issues.
I wasted hours because I forgot to restart the supervisor.
And yet, the article is just three lines long!!!
Please be careful, everyone. That's all.





