I just pushed a example on how to create a ChaosMonkey with the Slim framework to github. The idea is that whenever you create a webservice with the Slim framework (which is really simple) you rarely test for failure, the ChaosMonkey class will help you to do just that. When initialized with the AbsoluteChaos plugin it will randomly kill the webservice with exceptions, garbage to the output, or just run the service for you without failure at all.
One of the things it also can do is to delay the request with a sleep() call before it resumes the request, this is really important if you do REST calls from the interface: you have to check for network problems.
The AbsoluteChaos plugin does everything right now (as a example on how to do it) but I would suggest extending this for your needs, ex: create a ChaosMonkey_NetworkSleepChaos plugin. Or how about a plugin that can interfere with a bigger part of your system (kill of your mysql connection?) – anything is possible.
The following shows how to bootstrap ChaosMonkey together with the Slim framework.

 * Assuming Slim/ is in your include path
 * ini_set( "include_path", ini_get("include_path") . ":../Path/To/Slim");
 * Assuming ChaosMonkey is in your include path
require 'Slim/Slim.php';
require "ChaosMonkey/Chaos/AbsoluteChaos.php";
require "ChaosMonkey/Monkeys/Slim.php";
// First: initialize Slim
$app = new Slim();
// Create the Slim ChaosMonkey
$chaos = new ChaosMonkey_Slim( $app );
// We want to create a lot of havoc:
$chaosrunner = new ChaosMonkey_AbsoluteChaos();
 * For no chaos at all
 * $chaosrunner = new ChaosMonkey_NoChaos()
 * $chaos will now attach itself to one of the Slim hooks
$chaos->run( $chaosrunner );
$app->get('/', function () {
    echo "Hello, world";

Any other ideas on how to use this?

Write a Reply or Comment

Your email address will not be published.