PHP's MySQL connection timeout
TweetIn your php.ini you will find a value called mysql.connect_timeout. In the PHP ext/mysql it defaults to 60 seconds. Likewise, the php.ini has the same value. As far as I can tell, this timeout only comes in to play when the server is completely offline. If the server is up, but mysqld is not, the server refuses the connection immediately. I suppose if the server was under high load it could be used as well.
Well, IMO, 60 seconds is way to long to wait on a connection to the database for a web application. We had a server offline and expected the mysql_connect() call to simply fail due to the server not being up. However, it was waiting 60 seconds every time for the connection. This caused the PHP processes to hang and caused huge load on the servers.
So, what should it be? Well, the default MySQL connection timeout was 5 seconds up until October when it was changed to 10. I can't find why it changed. But, anyhow, IMO, a timeout of 5 seconds should be plenty for a web application.
I am working on a patch that I hope will be accepted to the PHP ext/mysql to set this to something more sane. Just have to find time to do it right, on all the branches and get the email written.
doughboy Says:
Yes, Dr. Tool, I have seen that issue before too. But, this was not the case. We use IP addresses for this very reason. We also disable reverse lookups in MySQL.