$pdo = new PDO('mysql:host=localhost;dbname=reacher', 'root', 'xxxxxxxxxxxxxxx',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbOptions = array( 'db_table' => 'Base_Sessoes_Symfony', 'db_id_col' => 'session_id', 'db_data_col' => 'session_value', 'db_time_col' => 'session_time',);
$session = new SessionProvider( new Chat() ,new Handler\PdoSessionHandler($pdo,$dbOptions));PHP 5.5.14 (cli) (built: Jun 27 2014 11:23:47)Copyright (c) 1997-2014 The PHP GroupZend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend TechnologiesPDOException was thrown when trying to read the session data: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
$pdo = new PDO('mysql:host=localhost;dbname=reacher', 'root', 'xxxxxxxxxxxxxxxxxxx',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",PDO::ATTR_PERSISTENT => false));
I ran into similar issue not with PDO but reactphp-mysql (for non-sessions related stuff).
I solved mine by creating a query() wrapper function, which would catch disconnect exception and reconnect.
try { $this->connection()->query("SHOW STATUS;")->execute();
} catch(\PDOException $e) {
if($e->getCode() != 'HY000' || !stristr($e->getMessage(), 'server has gone away')) {
throw $e;
}//Only reconnect if mysql error is gone away $this->reconnect();
}
public function reconnect()
{ $this->pdo = null;
return $this->connect();
}
public function connect()
{ $this->pdo = new PDO($this->dsn, $this->username, $this->password, (array) $this->driver_options);
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $this->pdo;
}
$this->reconnect();
public function onMessage(ConnectionInterface $from, $msg) {
//Synfony2 Stuff two detect if it is admin:
$Admin_Id = $conn->Session->get('admin_id');
if(isset($Admin_Id) && !empty($Admin_Id)){
echo "New ADMIN conection ({$conn->resourceId})\n";
//Admin stuff here
}else{
echo "New CLIENT conection ({$conn->resourceId})\n";
$this->WebSid_Conexao[$conn->resourceId]->send($json);
}New CLIENT connection (195)
session.cookie_domain = ".site.com.br"