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
  • 12,116
  • 6
  • 37
  • 66
user2264941
  • 407
  • 1
  • 8
  • 23
  • 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
  • 407
  • 1
  • 8
  • 23