drAkismetPlugin - 0.3.3

Interface for the Akismet spam detection web service

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source


This plugin is a library on top of the Akismet API. It is a spam detection tool leveraged by a web service. Read their online documentation for more information on the available calls.

Installation and configuration

  1. Download the plugin and copy it to your project's plugins directory
  2. Enable the plugin in your ProjectConfiguration class (/config/ProjectConfiguration.class.php)
  3. Create a configuration file akismet.yml
  4. Enter your API key(s): signup


API calls

The 1.1 API supports four methods:

Use a drAkismetApi instance to call theses methods:

$api = new drAkismetApi();
$verifyKey = $api->verifyKey() // or: new drAkismetApiVerifyKey();
$api->call($verifyKey); // returns a drAkismetApiReponse
// or alternatively you can directly do:
                 ->isValid($api); // returns TRUE / FALSE

Or use the drAkismetApiComment helper class - which can be extended by your own comment class:

$api = new drAkismetApi();
$checkComment = new drAkismetCheckComment();
$comment = new drAkismetApiComment();
             ->isSpam($api, $comment);


Calls to an API method return an instance of drAkismetApiReponse. The four provided methods return a subclass of said response class:

  • verifyKeyResponse has a method isValid (returned by verify-key)
  • checkCommentResponse has a method isSpam (returned by comment-check)


Use drAkismetValidatorSpam to validate comments directly from your forms. Of course, like any sfValidator, you can also use it outside your forms:

new drAkismetValidatorSpam(array(
        'blog'                 => 'http://www.symfony-project.org/blog/',
        'user_ip'              => $_SERVER['REMOTE_ADDR'],
        'comment_author'       => 'viagra-test-123',
        'comment_author_email' => 'foo@bar.net',
        'comment_content'      => 'test'

And more ...

It is possible to create your own connection class (socket connection by default) or to override the request parameters (e.g. for testing purposes):

class myConnection implements drAkismetConnectionInterface
  /* ... */
$api = new drAkismetApi();
$api->setConnection(new myConnection());

The default connection class drAkismetApiSocketConnection sends two events that you can use to monitor server requests and responses:

$api = new drAkismetApi();
// drAkismetApiSocketConnection::EVENT_PRE_REQUEST
                     ->connect('akismet.pre_request', array('listenToPreRequest'));
// drAkismetApiSocketConnection::EVENT_RAW_RESPONSE
                     ->connect('akismet.raw_response', array('listenToRawResponse'));


User agent

The defaults in the config directory of this plugin should suffice, but your are free to alter them.

API keys

For each host you can configure different API keys. You can also override the hostname that will be used when communicating with the Akismet service:

     www.yourhost.com: 123abc456def # the API key for said host
       host: www.yourhost.com # the hostname to use (instead of mydev.local)
       key:  123abc456def

Deny calls

You can limit the available API methods by using the allow_calls key:

  allow_calls: [check-comment] # one or more of: verify-key, check-comment, submit-spam, submit-ham