tags:

views:

104

answers:

3

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?

+2  A: 

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).

nickf
+3  A: 

If it was on another machine you could unplug the network cable!

Toby Allen
simple and effective
Jacco
+3  A: 

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

Gordon