JMSJobQueueBundle icon indicating copy to clipboard operation
JMSJobQueueBundle copied to clipboard

MySQL server has gone away from cron scheduler

Open Xymanek opened this issue 7 years ago • 1 comments

I made a cron command using ScheduleEveryOtherMinute trait, however the scheduler crashes every second time it tries to create the job with Warning: PDOStatement::execute(): MySQL server has gone away exception.

A possible fix for this would running something like this every loop iteration:

if ($em->getConnection()->ping() === false) {
    $em->getConnection()->close();
    $em->getConnection()->connect();
}

If I recall correctly, the EntityManager doesn't get closed if you disconnect/connect the underlying connection manually so the rest of code should work without any changes.

If every loop iteration seems excessive then perhaps an option like --conn-ping-interval which will allow to define a custom interval to run the code above.

Thoughts (I can make a PR)?

Xymanek avatar Jul 07 '17 19:07 Xymanek

Seems like a good idea to add.

schmittjoh avatar Jul 24 '17 12:07 schmittjoh