Created
November 7, 2017 04:41
-
-
Save lf-uraku-yuki/519038e8e5b87bb8c17c3feb0b03238b to your computer and use it in GitHub Desktop.
Codeigniter 3.x Database Connect Retry Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function reconnectDb() | |
{ | |
if ($this->db->conn_id !== false) { | |
return; | |
} | |
log_message('error', 'DB接続失敗。再接続開始'); | |
// スクリプト実行可能時間を延ばしておく | |
ini_set('max_execution_time', '180'); | |
for ($retry_count = 0; $retry_count < 8; $retry_count ++) { | |
sleep(15); | |
$this->load->database(); | |
if ($this->db->conn_id !== false) { | |
log_message('debug', 'DB再接続処理OK'); | |
return; | |
} | |
log_message('debug', 'DB再接続処理NG'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
目的
前提・用途
注意点