We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Too Many Connections error when using Mysql database.

Am having a problem with phalcon not closing db connections. In my.cnf file I have set max_connections = 10000.

But after some hours I have to restart my VPS in order to get rid of the 'Too many Connections' error.

Have set db as shared, set persistent to true, all as troubleshooting measures but still gets the connection error.

I will be happy for a solid suggestion.

edited May '18

After commenting any persistent set and leaving db as Shared

seems the connections are being closed now.

Am using below ssh command to monitor

watch -n1 "netstat -np | grep -i mysqld"

Am not going to mark this as the answer now but after days of monitoring and veiwing the perfomance I will update here

run SHOW PROCESSLIST on mysql when you access the page too see how many connections their are and what commands they are running.

edited May '18

Well if you set persistent DB connections, what would you expect?

PDO::ATTR_PERSISTENT => true

// Many web applications will benefit from making persistent connections to database servers. Persistent connections are not closed at the end of the script,
        // but are cached and re-used when another script requests a connection using the same credentials.
        // The persistent connection cache allows you to avoid the overhead of establishing a new connection every time a script needs to talk to a database, resulting in a faster web application.

However, that shall be used with caution and general recommendation is to leave it disabled.