SQL, PHP - Close a sleeping connection

a 夏天 提交于 2019-12-13 05:45:30

问题


Good day to all. I have a little problem:

How do I close the sleeping connections to a database?

When I issue a query the query is executed then the connection remains on sleep mode for 2-3 seconds. The problem is that I generate queries faster than they are closed.

Is there a way to force a connection to close before entering in the sleep mode? Or any workaround.

Thank you for help.

Note: The connections are not permanent, they close, but just to slow... Note 2 - for the mysql_close(): The command is issued at the end of the query. Still the query goes into sleep mode before close. I attach a print screen in a min.

Notice the sleeping connections... they will be closed in 1-3 secs... but I generate another queries faster. I need to skip the sleep wasted time.


回答1:


Are you using mysql_pconnect() ? If not, this should not happen if you properly close every connection made to your database.

Edit : Similar issue ?




回答2:


Explicitly. For example, if you are using mysql then call mysql_close(). Or the equivalent for whatever database you are using.




回答3:


my class for dbconnection hast mysqli_close($this->conn); in its __destruct() so that every connection is closed on destruction of the connection.




回答4:


Try setting the wait_timeout variable = 1 so they will close after 1 second.



来源:https://stackoverflow.com/questions/5041795/sql-php-close-a-sleeping-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!