Sleep until database avaible connection quota

As i saw, database allowing max 2 connections. Which is very very low, sadly.
So i thought maybe i can edit laravel core to make it if database indicating it’s connection quota is full, then wait for a moment and try again x times until ready.

Well, as may you know sleep function is disabled for security and performance reasons. So, i need a better plan.

correct me if I’m wrong, but it seems like the max connections is still set to 10.

8 Likes

Going to have to agree with @wackyblackie on this one. Can you show your proof as to why it’s been reduced from 10?

8 Likes

1 Like

Any updates on this matter? @Greenreader9

Unable to raise it to 10. As expected.

Here’s why

Pretty sure doing any kind of operation which requires the permission which you lack is going to fail either way…

2 Likes

The max_user_connections limit is set to prevent a single account from overloading the database server. Because of that, the limit cannot be increased.

In most cases I see where people hit this limit, it’s caused by opening multiple database connections with every request. But Laravel should handle that for you, so as long as you’re using Laravel’s database handling functionality (Elouqent and Query Builder), you shouldn’t have this issue.

If you are manually opening additional database connections, through PDO or MySQLi for example, then the solution is very simple: don’t do that.

I’m not sure how you were planning to implement that connection retry mechanism, because as far as I know, Laravel doesn’t offer anything like that. Which implies to me you’re hacking the database logic yourself, which may actually be causing the problems you’re having, not solving it.

Retrying the database connection with a sleep() in between is a really bad idea for many reasons. First of all, you’re replacing random errors with some requests randomly taking a REALLY long time to process. Additionally, all the sleeping processes will cause your entry process usage to shoot up, which will cause different errors on your site.


TL;DR: Forget about the connection retry. If it fails, just let it fail. Make sure you’re only opening one connection per request (i.e. make sure you only use the database connection created by Laravel itself). If this solves the problem, you’ll need to upgrade to premium hosting to increase the limit.

9 Likes

Problem occurs when multiple users surfing on site. Account upgrade required anyway.

Hey there @wiselycursedB :wave:
Noticed your issue was solved, great!

To help you combat this in the future, I’ve linked below to a snippet of the Laravel 10 documentation that you could use to help monitor your database connections.

https://laravel.com/docs/10.x/database#monitoring-your-databases

if you use a different version of Laravel, please notify me and I will update this post promptly.
Cheers :tada:

6 Likes

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