XF 1.5 Too Many Connections - Query is hanging somewhere

Sean Kendle

Member
We have been getting the dreaded "Too Many Connections" error, and while I know that we can increase the number of connections, this is not the problem. The problem according to our host is that there is a query somewhere that is hanging, or potentially running and then leaving the connection open. I suspect it's from an add-on that I installed or maybe one I wrote.

1. Is there a specific way to query the database that might leave the connection open?

In my own add-ons I've been using `fetchAllKeyed()`. Does this function take care of closing the connection, garbage collection and the like?

I also found these in other add-ons, do any of them potentially open a connection without closing it? (I've removed arguments for brevity)

$this->_getDb()->fetchRow();
$db = $this->_getDb();

2. Also, is there some way to find out which query might be hanging? An Add-on or some feature I've not found in the Admin CP?

Thanks!
 

Jake B.

Well-known member
The functions you've listed are just used to run queries, your host should be able to get you the hanging query
 

Sean Kendle

Member
We're waiting on that information. I know they're used to run queries, but do they open a database connection without closing it, is my question?
 

Snog

Well-known member
MySQL connections close automatically when the PHP script finishes running. Or they are suppose to.
 

Sean Kendle

Member
Open non-persistent MySQL connections and result sets are automatically destroyed when a PHP script finishes its execution. So, while explicitly closing open connections and freeing result sets is optional, doing so is recommended. This will immediately return resources to PHP and MySQL, which can improve performance. For related information, see freeing resources
From: http://php.net/manual/en/function.mysql-close.php

However, I'd much rather know for sure my connections are being closed as soon as possible. This board is very big and very busy, so any efficiency gains are very welcome.
 

Snog

Well-known member
From: http://php.net/manual/en/function.mysql-close.php

However, I'd much rather know for sure my connections are being closed as soon as possible. This board is very big and very busy, so any efficiency gains are very welcome.
All that does is close the connection before the PHP script ends.

And:
Open non-persistent MySQL connections and result sets are automatically destroyed when a PHP script finishes its execution.
Destroyed is another word for closed. ;)

In most cases, the amount of time a PHP script runs is so small that closing the connection before the end of the script would result in little to no gains.
 

Sean Kendle

Member
Either way, I suspect it has more to do with a poorly formed SQL statement taking an overly long time to complete more than a connection left open, knowing what I now know. Thanks! I guess we'll wait for the hosting company to get back to us with which query is hanging.
 
Top