1

I keep getting this error incessantly. How do I avoid it with Yii? I saw some questions about Yii 1 but they use options that aren't in the documentation: http://www.yiiframework.com/doc-2.0/yii-db-connection.html, http://php.net/manual/en/pdo.setattribute.php

Error: PDOStatement::execute(): MySQL server has gone away

The query is normally very simple.

The SQL being executed was: SHOW FULL COLUMNS FROM ad_group_keyword

I'm using MySQL (from ClearDB) and I don't have access to the server configurations.

I added these attributes to the db but they did not help.

'attributes' => [
  PDO::ATTR_PERSISTENT => false, // ClearDB connection limit is 90s
  PDO::ATTR_TIMEOUT => 90,
  PDO::MYSQL_ATTR_INIT_COMMAND => 'select 1',
]
Chloe
  • 25,162
  • 40
  • 190
  • 357
  • That might not be a problem of Yii, but rather your server. It sounds like the server blocked the attemt to connect to it. – DocRattie Sep 02 '15 at 09:41
  • It works most of the time. But 1-2% failure rate is too high. – Chloe Sep 02 '15 at 09:42
  • how about a little timer event you call every 60 seconds that says `select 7;` ! it is a timeout issue with settings – Drew Sep 02 '15 at 09:47
  • Ok but how do I do that in Yii2? I didn't see an option in the docs for a timer callback. I seem to remember that option in Hibernate. – Chloe Sep 02 '15 at 19:44
  • Adding this to the `db` seems to have mitigated it, but not eliminated it: `'attributes' => [ PDO::ATTR_PERSISTENT => false // ClearDB connection limit is 90s ]` – Chloe Sep 06 '15 at 17:29

1 Answers1

0

Ok I solved this by migrating away from MySQL on ClearDB. I wasn't the only person with this problem. https://www.designedbyaturtle.co.uk/2015/dedicated-vs-shared-databases-a-mysql-has-gone-way-fix/

I migrated from MySQL to Heroku Postgres. https://stackoverflow.com/a/16732524/148844

Community
  • 1
  • 1
Chloe
  • 25,162
  • 40
  • 190
  • 357