Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySQL server has gone away #51

Closed
sproogen opened this issue Jan 19, 2017 · 2 comments
Closed

MySQL server has gone away #51

sproogen opened this issue Jan 19, 2017 · 2 comments

Comments

@sproogen
Copy link

Hi,

We are having this issue after an extended period of inactivity, usually overnight, where when the first query after this period is throwing this error Warning: PDOStatement::execute(): MySQL server has gone away

We put in a fix for this by closing and reopening the database connection but this just threw a new issue after the inactivity of Warning: Error while sending QUERY packet.

Has anyone had this before or know of a fix for this? It looks like it is happening after the 8 hour wait_timout in mysql.

I have also seen there is a cleanup function in the WampKernel that looks like it should be resetting the connections?

Thanks

@stingus
Copy link
Contributor

stingus commented Jan 19, 2017

If you're using Doctrine, you can use the following:
$em = $this->doctrine->getManager(); $dbalConn = $em->getConnection(); if (!$dbalConn->ping()) { $dbalConn->close(); $dbalConn->connect(); }

I had the same issue and the ping() test fixed it. You just need to figure out where to place the test, like an entry point. I use it in an authentication provider (JWT), because all requests triggering connections to MySQL are passing through that method.

@sproogen
Copy link
Author

Thanks @stingus, it looks like we were doing the close and connect at the start of an action but after the authentication call.

Having moved it to the start of out Authentication Provider it seems to be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants