Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

handisb's avatar

Allowed Memory Size Exhausted Error in Laravel Application

Hello!

I keep getting an error in our Laravel application that says "Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes)". I've increased the PHP memory limit to 2GB but I still keep getting this error. Our databases are a little more than 1GB in size, so I'm not sure if that could be the issue?

Any help would be greatly appreciated!

0 likes
6 replies
Sinnbeck's avatar

Seems that the change isn't registered. The error is for 128mb. Maybe restart the php fpm process if using nginx

But best of all you should optimize your code. 128mb is a lot for a single call (i hope it's at least a command or job that uses this much memory)

Database size has nothing to do with this btw

Tray2's avatar

That means that you tried to load too much into a single view. Since you aren't sharing any code at all I would suggest you look at the controller and the database query that you call.

Theresanowak's avatar

The error message you are receiving indicates that your PHP script has exceeded the memory limit allocated by PHP. Increasing the PHP memory limit to 2GB should be more than enough for most applications, but it's possible that your application is using more memory than anticipated.

The size of your database may contribute to the issue if you are loading large datasets into memory or running complex queries that require significant memory usage. However, it's important to note that the size of your database alone should not cause your application to exceed the memory limit.

There are a few potential solutions you could try:

Optimize your code: Review your code to identify any areas https://www.tellhappystar.org/ where you could be using more memory than necessary. For example, you could optimize loops, reduce the number of database queries, or use more efficient data structures.

Increase memory limit: You could try increasing the memory limit further. However, increasing the memory limit too much could cause other issues, such as slowing down your server or causing it to run out of memory.

Use pagination: If you're loading large amounts of data into memory, consider using pagination to limit the amount of data loaded at once.

Use caching: You could use caching to reduce the amount of data loaded from the database on each request. This can help reduce memory usage and improve performance.

Optimize database: Consider optimizing your database, such as indexing tables or removing unnecessary data, to reduce the amount of memory required to run queries.

venoel's avatar

One of the reason (not excepting mentioned above) getting "Allowed Memory Size..." is not enough rights on file "./storage/logs/laravel.log" for web-server.

Please or to participate in this conversation.