5

I have a long-running job, built using Propel2. However, sometimes it crashes with the infamous mysql server has gone away error. I'd like to recover from this error by reconnecting to the server, maybe after waiting a few seconds. Does anyone have an idea how to force Propel to reconnect after the connection has been lost? I didn't find any clues how to do this from the Propel or PDO API.

  • I am having same issue . I tried to set persistent connection , but don't think this will help. – Vahan May 30 '16 at 13:07

1 Answers1

5

I ran into this issue when in combination with laravel queue. The queue:work daemon is process, after timeout occurs, it does not reconnect by itself. Tried persistent connection as well, that didn't help.

The way I have solved this now, is a little queue/laravel specific, but might help you get to a solution too.

I now force each job that gets handled by the worker, to disconnect the propel connections by using Queue::before() event.

$manager = Propel::getConnectionManager('default');
$manager->closeConnections();

New requests done by Propel will then create a new connection (this will happen for each new job that is handled by the worker though)

You could perhaps try/catch your query, see what the error/exception is, and when it's 'mysql server has gone away' trigger a disconnect and retry the query

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Leentje
  • 134
  • 2
  • 14