CodeIgniter数据库连接未关闭 [英] CodeIgniter database connections not being closed

查看:206
本文介绍了CodeIgniter数据库连接未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在CodeIgniter建立了一个社交网站,现在得到一个公平的交通,主机公司已经开始抱怨说,数据库正在接收空连接以及未关闭的连接。 p>

我不完全确定一个空查询是什么,或者如何结束发布,任何想法?



我已经添加了额外的代码,以强制关闭连接,当代码到达结束,但显然这不工作。



任何人都可以提供任何建议,开始调试这样的问题?



感谢



我的核心底部有以下内容 MY_Controller

  public function __destruct(){
$ this-> ; db-> close();
}


解决方案



在此页面上,您可以看到配置数组中的每个值:

http://ellislab.com/codeigniter/user-guide/database/configuration.html

  $ db ['default'] ['hostname'] =localhost; 
$ db ['default'] ['username'] =root;
$ db ['default'] ['password'] =;
$ db ['default'] ['database'] =database_name;
$ db ['default'] ['dbdriver'] =mysql;
$ db ['default'] ['dbprefix'] =;
$ db ['default'] ['pconnect'] = TRUE;
$ db ['default'] ['db_debug'] = FALSE;
$ db ['default'] ['cache_on'] = FALSE;
$ db ['default'] ['cachedir'] =;
$ db ['default'] ['char_set'] =utf8;
$ db ['default'] ['dbcollat​​'] =utf8_general_ci;
$ db ['default'] ['swap_pre'] =;
$ db ['default'] ['autoinit'] = TRUE;
$ db ['default'] ['stricton'] = FALSE;

这是一个基本的数组配置数据库,尝试将pconnect的变量设置为FALSE,打开后,系统不会关闭任何连接,并且随时保持对新闻查询打开。



如果像我说的那样将其设置为false,系统将继续工作完美,但是当他需要使用数据库时,codeigniter将关闭并打开连接。



在这里,你可以找到和发布内部codeigniter论坛,有pconnect变量的问题,可以帮助你!
http://codeigniter.com/forums/viewthread/177573/#842016


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 receiving null connections as well as connections which aren't being closed.

I am not entirely sure what a null query is or how one would end up being issued, any ideas?

I have added in additional code to force close connections when the code reaches an end but apparently this isn't working.

Can anyone offer any suggestions as to where to look or start debugging an issue like this?

Thanks

I have the following at the bottom of my core MY_Controller

public function __destruct() {
    $this->db->close();
}

解决方案

I think that you're gettting problemns with the initial configurations from Codeigniter connection database.

At this page, you can see each value from config array:
http://ellislab.com/codeigniter/user-guide/database/configuration.html

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "database_name";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = "";
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

This it's an basic array config database, try to set the variable of pconnect to FALSE, when it is turned on, the system doesn't close any connection and it stay opened to news queries at any time.

If you set it to false like i said, your system will continue working perfectly, but the codeigniter will close and open the connection when he need's to use the database.

Here, you can find and post inside codeigniter forum with a guy that's have a problem with pconnect variables, may help you! http://codeigniter.com/forums/viewthread/177573/#842016

这篇关于CodeIgniter数据库连接未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆