Rediska

Follow me on twitter…

Profiler

Rediska provide a few profilers which monitor execution of all Rediska commands.

Profiler is a nice tool for big projects and optimiazation, but don't use it in production!

For enable profiler you can change profiler option:

  • true - default profiler gather stats about all executed commands and you can get its by Rediska#getProfiler() method.
  • Array with key name wich value is name of profiler (stream for example) or class name wich implements Rediska_Profiler_Interface. Other keys passed as options to profiler.
  • Object wich implements Rediska_Profiler_Interface.

Stream

Let's save profiler results to stream:

<?php

$options = array(
    'profiler' => array(
        'name'   => 'stream',
        'stream' => 'profiler.log',
        //'mode' => 'a',
        //'format' => '[%timestamp%] %profile% => %elapsedTime%'
    )
);

// Execute some commands
$rediska = new Rediska($options);
$rediska->set('a', 5);
$rediska->increment('a');

// Look to profiler.log for their profiles

// You can get command profiles in you code
foreach($rediska->getProfiler() as $profile) {
    echo $profile->__toString();
}

?>

Firebug

With FirePHP and Zend Framework you can write you profiles to a Firebug:

<?php

$options = array(
    'profiler' => 'Rediska_Zend_Profiler_Firebug'
);

// Execute some commands
$rediska = new Rediska($options);
$rediska->set('a', 5);
$rediska->increment('a');

?>

Comments

Josh May 01, 2011 19:53

Trying the Firebug profiler from the example on http://rediska.geometria-lab.net/documentation/configuration/profiler/

Fatal error: Uncaught exception 'Rediska_Exception' with message 'Profiler option must be a boolean, object or array of options' in /usr/local/lib/php/Rediska.php:550 Stack trace: #0 /usr/local/lib/php/Rediska.php(587): Rediska->getProfiler() #1 /usr/local/lib/php/Rediska.php(786): Rediska->_executeCommand('set', Array) #2 /var/www/rediska/test2.php(10): Rediska->set('a', 5) #3 {main} thrown in /usr/local/lib/php/Rediska.php on line 550

Code:
http://pastebin.com/5yYmBCp2

Ivan Shumkov May 24, 2011 08:58

I'm fixed this bug at master on github.

Fork me on GitHub