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?
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?
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).
If it was on another machine you could unplug the network cable!
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