1
我有一個在循環中連續運行的Shell腳本。cakephp 3.1 mysql已經消失
它檢查數據庫中的記錄並在需要時更改它們。我有
set_time_limit(0);
while(true){
try{
$this->out(mysql_ping());
$companies = $this->findCompanies();
$companies = $this->reduceCompanies($companies, $rules);
$this->processCompanies($companies);
}catch (\Exception $e){
Log::write('debug', $e->getMessage());
$this->out($e->getMessage());
}
sleep(3);
}
問題是這樣的劇本似乎運行正常,但然後隨機將拋出: 「2006年MySQL服務器已經走了」 我試圖把一些東西在異常俘獲重新連接到mysql服務器如:
}catch (\Exception $e){
if(!mysql_ping()){//tried
$this->connection->reconnect(); //also tried
$this->Company->getDatasource()->reconnect(); neither seem to work.
}}
任何建議如何重新連接到數據庫?
我面臨着類似的問題,我們需要去的根本原因這,這應該是理想情況下不會發生:( –