CodeIgniter database connections not being closed

前端 未结 6 1429
灰色年华
灰色年华 2021-02-05 04:48

I have built a social community website in CodeIgniter which is now getting a fair bit of traffic, the hosting company have started complaining and saying that the database is r

6条回答
  •  渐次进展
    2021-02-05 05:33

    I have had similar problems with CodeIgniter in the past and they were caused by persistent connections in MySQL which is enabled by default in CodeIgniter. I used the SHOW PROCESSLIST query in MySQL to view open connections, their current running query, the time (in seconds) the connection has been open for, etc. If the connection is idle the Command field returned would contain Sleep and the Info field (the query) would be NULL which is probably what your host is referring to. That's a good place to start with an issue like this.

    Another thing that I want to note is a nuance of PHP, mysql_close which is being called here from your controller's __destruct method will not close a persistent MySQL connection. PHP will close non-persistent connections at the end of the script's execution so it is usually not necessary to call it.

    I realize that you had said persistent connections were not enabled, this was how I went about debugging my problem which sounds very similar to your problem.

提交回复
热议问题