does Yii automatically close connection?


Might be a stupid question, but does Yii automatically close connection to DB?

I mean do I have to call

Yii::app()->db->active = false;

everytime the script finishes all jobs?

Thank you.

Resources that have no more reference will be detected and free by PHP garbage collector. So you can assume it is safely closed when a request has ended.

Then how come I am receiving this error?

Number of connections in a pool is limited in MySQL config. When there are many clients coming at the same time, too many connections are opened simultaneously. Each connection stays for the duration of the request/response cycle. For example, if it’s 300ms and your pool can accept 100 connections at the same time then at about 330 requests per second the error would appear.

I have a confuse.
Recently my vps have runout the tcp connect that there is too many connections in wait time and never been freed, is this because that the connection never been closed?
Should the response class or some components has some feature to config that the behavior auto send close command after the content is sent?

Usually that is the case. The fundamental reason could vary though. It could be long processing, slow responses, concurrecy issues and more.

Will the response class or the connect components have some feature to auto close themselves?
Or someway, could I write some feature and submit a PR to do this?

No. That won’t help in most cases.

Get it, I will thinking other ways to reduce the connections.
And that, I know it’s very unreasonable, but, emmm do you have some advice for this? Thanks very much.

When it will start erroring, check what happens in the database by executing following SQL:


That would give you enough info to start with.