Database issue

The limit for max_user_connections on InfinityFree is only 4. This should be plenty for most websites, assuming your code only opens one database connection per request, and closes them when done.

I took a quick look at your code, and the general setup seems to be put quite well together, and you already have a single database connection being passed around, so that’s good!

In the database setup code, you do appear to have one particular option enabled that’s causing all of your problems: persistent MySQL connections.

This option doesn’t work well on our hosting, and may not work at all. In very specific server setups (if you have your own server with PHP-FPM for example), it can work, but on a shared server that’s set up the way we’ve set up our hosting, enabling Persistent Connections just results in a large number of connections that are open simultaneously but cannot be used by your application.

Here is another topic from some time ago where someone else had a similar problem with persistent connections:

For you, the solution is much simpler though, no need to refactor your code. All you need to do is disable MySQL Persistent Connections and you shouldn’t ever see this error again.

5 Likes