Skip to content

Databases

Connection limits

Learn what max_connections limits, why the site looks down when you hit it, and how to size PHP and MySQL without wasting RAM.

Updated Aug 29, 20263 min read21 reads
Connection limits
MySQL max_connections and what hits the ceiling

Connection limits control how many clients can talk to MySQL or MariaDB at once. The server variable max_connections is a hard ceiling on open threads, not a speed setting. When you hit it, your app often looks like the database is down even though the service is still running.

What max_connections actually means

Each PHP worker that needs the database can hold one MySQL connection while it runs. If workers wait on slow queries or stay open with persistent connections, those slots fill up fast. On a VPS you can check the live picture with simple SQL.

code
SHOW STATUS LIKE ‘Threads_connected’;
SHOW VARIABLES LIKE ‘max_connections’;

When Threads_connected sits near the ceiling, new requests fail with connection errors. Monitoring may still show MariaDB as up, because the daemon is fine and only the free slots are gone. On shared hosting you cannot raise that ceiling yourself, and you usually should not need to. CloudLinux LVE already limits how many PHP processes your account can run, and that process limit is the real cap in practice.

Why raising the ceiling is often the wrong fix

Pushing max_connections very high on a small VPS trades one outage for another. Every connection uses RAM for stack and session buffers, even when the client is idle. A thousand parked threads do not mean more real traffic handled. They mean more memory spent on waiting clients. LiteSpeed cache, an object cache, and a PHP-FPM pool sized so workers finish work will serve more users than a huge pile of idle MySQL threads.

After a large import, connections often pile up because every page is slow and every worker stays busy. That is an import or query problem wearing a connection mask. If the timing matches a restore, see MySQL slow after a big import.

How to size things on VPS and dedicated

On a dedicated server you can afford a higher ceiling when you have the RAM to match. On a small VPS, size PHP children first, then set max_connections a bit above that number. Leave a few slots for cron jobs and your own admin session. Hitting about ninety percent of the ceiling on a quiet day is your early warning. Persistent connections plus PHP-FPM can exhaust slots with fewer visitors than you expect, because each idle worker still holds a thread in MariaDB. Prefer short-lived connections and caching so routine page views never need the database at all.

Share

Send this article

Need someone else to do this? Send them the link — the commands are in the article.

Was this article helpful?

Be the first to rate this article.