0

I have workers that works on php (yii2) under supervisord.

I using persistant connection for MySQL DB.

'attributes'=>[
    PDO::ATTR_PERSISTENT => true
]

But it refused after 8 hours.

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away. 

I think that it already was realised.

How I can automatically reopen persistent connection?

CodeGodie
  • 11,914
  • 5
  • 35
  • 64
user2264941
  • 387
  • 6
  • 21
  • 2
    Possible duplicate of [PDO: MySQL server has gone away](http://stackoverflow.com/questions/2232150/pdo-mysql-server-has-gone-away) – LFI Mar 01 '16 at 14:30
  • I had the same problem, and in the end I'm not using persistent connections - the worker connects, does it's job, then disconnects. – Beowulfenator Mar 03 '16 at 12:40

1 Answers1

0

I have done this way:

try {
    ...
} catch (...) {
    Yii::$app->db->close();
    Yii::$app->db->open();
    ...
}
user2264941
  • 387
  • 6
  • 21