I have a yii-powered website using a mysql database. When i run show processlist in the mysql I see many sleeping connections, which I think means that the database connection is not being closed by Yii?
I also tried to see if the Yii::app()->db->close() function is ever being run but it doesn’t seem to be… or maybe I am not checking properly.
Anyway, my question is: Does Yii close the database connection after a page is loaded? If not, how can I do it so Yii does close the DB connection once done with it?
There’s a very similar post here: http://www.yiiframework.com/forum/index.php?/topic/11255-does-yii-automatically-close-connection/
Basically, Yii doesn’t do it automatically - the PHP runtime will identify ended requests and close the connection.
Don’t know about MySQL connections but if you’re right, and I guess you are, then the garbage collector of PHP should close them.
But, you have to make sure that garbage collector runs. this is not that obvious on certain PHP stock configurations. I’ve written a post about this exact issue some time ago. See it here.