28
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CodeIgniterAdvent Calendar 2013

Day 6

CodeIgniterの怖いデフォルト設定 - database.php

Posted at

まず、結論から

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = ''password;
$db['default']['database'] = 'database';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$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'] = FALSE;
$db['default']['stricton'] = FALSE;

こうした方がよくて、デフォルトと何が違うかっていうと

$db['default']['pconnect'] = FALSE;
$db['default']['autoinit'] = FALSE;

この二つです。

前々からCodeIgniter使ってるときにDatabaseの最大コネクション数でエラーに陥っていました。

しょうがないので、データベースサーバのスケールアップとかで対応していのですが、実はこいつらの所為だったぽいのです。

こいつらなんなのかというと、

  • pconnectはDBと永続的な接続を行う
  • autoinitはモデルが生成されたとき?に勝手にデータベースを初期化する

これらで接続数が稼がれていたようです。

接続数でお困りの方はこれらをFALSEにするのをおすすめします。

28
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
34

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?