I have a cron job that runs every minute. Every once in a while the cron fails with the error:
MySQL server has gone away
The problem is that all the query below this error are executed and may sometimes give undesirable result.
So how do I detect that the error has occurred and exit execution of rest of the code?
Or any hint on how to fix the error in the first place would be great.
The error seems to be caused by connecting to a server that isnt responding, or you are using a persistent connection that is timing out.
You should be able to get some kind of error code from the client API, and catch to see if the connection is still valid.
If it has failed, you can throw an exception, and then stop the program.
Is what I use on my site