Using the show full processlist; command when connected to our app's mysql db, I can see processes that are in the SLEEP state.
It is not clear what is causing this, but I would like to try explicitly closing the db connection to see if that clears these processes.
My question is, where is the best place to do this? I was thinking in the after() method of the controller. Is there a better place?
I am also confused as to the best way to go about this. I see that the __destruct() method will close the connection, but I don't know exactly how to call that.
You don't need to do that, every Connection object has an __destruct() that will explicitly do a disconnect. If you don't trigger it with an unset(), PHP will trigger it when the request is finished.
If connections aren't closed, have you configured your application to use persistent connections (which will not be closed by the above mechanism)?
You can control the time the process waits for a new connection through the "wait_timeout" config setting in your my.cnf.
Thank you for your help with this. The app is running on Pagoda and the sleep processes do appear in between page requests, but sometimes it takes 4 seconds for a request to go through as a simple UPDATE query waits.
The sleep processes go away once the page is loaded, but there is an occasional one that will remain indefinitely.
So there is no need to close the connection manually?