does Yii automatically close connection?


(Yevreinov) #1

Hello.

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.


(Ngpeijiun) #2

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.


(Magezisagesse) #3

Then how come I am receiving this error?


(Alexander Makarov) #4

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.


(teng) #5

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?


(Alexander Makarov) #6

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


(teng) #7

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?


(Alexander Makarov) #8

No. That won’t help in most cases.


(teng) #9

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.


(Alexander Makarov) #10

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

SHOW FULL PROCESSLIST;

That would give you enough info to start with.