I'm running lots of cron job and once in a while there is a MYSQL has gone away error.
I've now written some code to handle the error, but how do I simulate the error on my localhost so that the code can be tested thoroughly?
The MySQL server has gone away error, means that MySQL server (mysqld) timed out and closed the connection. By default, MySQL will close connections after eight hours (28800 seconds) if nothing happens.
If it was on another machine you could unplug the network cable!
Kill a long-running thread.
See: KILL
syntax
The documentation about that error also lists different causes, so you could emulate some of them (eg: change the timeout to be very low, etc).
Mock the (affected method in the) Database adapter and have it raise the error. That's the usual approach when unit-testing code that has dependencies on external resources. If you are not using PHPUnit yet, this is a great opportunity to get started with it.
Further reading
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With