Every visit to a dynamic page opens a database connection, which stays busy until the page finishes. When connections pile up faster than they close, the server reaches max_connections and refuses new ones. In PHP the message reads:
SQLSTATE[HY000] [1040] Too many connections
WordPress visitors see Error establishing a database connection instead.
This is a server-wide limit. If your message mentions max_user_connections, you’re looking at error 1203, the per-user limit.
Causes
- Lots of traffic to uncached pages, from real visitors or bots.
- Slow queries: each request holds its connection longer, so connections stack up.
- Persistent connections via
mysqli_pconnectorPDO::ATTR_PERSISTENTthat stay open while idle. - Long scripts, cron jobs or background workers that open a connection and never close it.
- Locked tables (especially MyISAM) that make queries wait while holding their connections.
- A low
max_connectionson a self-managed server that was never tuned.
How to fix it
- Look at current connections in phpMyAdmin’s SQL tab:
SHOW PROCESSLIST;
On shared hosting you only see your own user’s connections. Lots of Sleep rows mean connections left open; lots of Query rows with a high Time mean slow queries.
- Turn off persistent connections in PHP:
$pdo = new PDO($dsn, $user, $pass, [
PDO::ATTR_PERSISTENT => false,
]);
-
Cache your pages. On WordPress, LiteSpeed Cache keeps most visits from touching the database at all.
-
Speed up slow queries with indexes. Check the query first:
EXPLAIN SELECT * FROM orders WHERE customer_id = 42;
CREATE INDEX idx_orders_customer ON orders (customer_id);
-
Close connections in long scripts once they’re done:
$pdo = null;in PHP, orDB::disconnect();inside a long loop in Laravel. -
Block abusive crawlers that request many pages in a short time, with
robots.txtor blocking rules.
On your own server
With root access, check the limit and the peak you’ve reached:
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Max_used_connections';
Then raise it in the MySQL or MariaDB config, as far as memory allows:
[mysqld]
max_connections = 300
Prevention
- Treat caching as part of the site, not an extra.
- Watch for slow queries after every new plugin or feature.
- In Node.js apps, use a single small pool instead of a connection per request.
On ArabyHost
Every ArabyHost account has a limit on simultaneous database connections, and there’s no root access to change server settings. So the fix is always on your site’s side: close connections when you’re done, avoid persistent connections, and cache. The web server is LiteSpeed, with LiteSpeed Cache for WordPress; the setup is in the WordPress speed guide. If the error keeps coming back, the Araby AI assistant reads your error log and shows when it happens and why.
FAQ
What's the difference between error 1040 and 1203?
1040 means the whole server reached its connection limit (max_connections); 1203 means a single database user reached its own limit (max_user_connections). Either way, the fix is fewer open connections.
Should I just raise max_connections?
On your own server you can, as far as memory allows, since each connection uses some. But it doesn't fix slow queries or connections that never close, so deal with those first.
Do persistent connections make a site faster?
They save the time to open a connection, but keep idle connections reserved. On hosting with a per-account connection limit they trigger this error sooner, so it's better to turn them off.