I have a Shell script that runs continuously on a loop.
It checks the database for records and alters them if needs be.
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);
}
Problem I'm having is this script seems to run ok, but then randomly will throw: '2006 MySQL server has gone away' I've tried to put some stuff in the exception catch to reconnect to the mysql server such as :
}catch (\Exception $e){
if(!mysql_ping()){//tried
$this->connection->reconnect(); //also tried
$this->Company->getDatasource()->reconnect(); neither seem to work.
}}
Any suggestions how to reconnect to the db?