Zend_Service_Mollom Documentation

Watch out!

Zend_Service_Mollom was written in 2008. It hasn’t been update for a few years now, so it might not work anymore.

Zend_Service_Mollom is a Zend Framework component for calling Mollom, a spam filtering and CAPTCHA service for blog comments and forum posts. This page serves as the project homepage, with download information and documentation.

Mollom? Zend Framework?

Mollom, like Akismet filters your user-submitted content. But with an approach that should work better. Mollom integrates automatic checking with CAPTCHAs. More info is available on the How Mollom Works page.

Zend Framework is a framework for building PHP applications. The Zend_Service_Mollom component integrates the two. Zend_Service_Mollom implements the full Mollom API and is tested using unit tests.


The latest version for Zend_Service_Mollom is v1.2.0. There are two ways to get it:

Changes compared to v1.1.0:

  • Integrate caching code, to prevent a getServers roundtrip on every usage. Improves performance.
  • Add unit test coverage for the caching code
  • This version will be proposed for inclusion in Zend Framework 1.8

A full changelog is available in the README.txt file. I am proposing this version for inclusion into Zend Framework 1.8. For now however, you will have to get your releases here.

Who wrote this? Who should I contact?

Zend_Service_Mollom was written by Ruben Vermeersch. All questions, remarks & feedback are welcome, I am also available for contracting on PHP related projects.

Using Zend_Service_Mollom

Assuming you have installed your Zend Framework application correctly, as well as the Zend_Service_Mollom files (install instructions can be found inINSTALL.txt), using Zend_Service_Mollom is just like any other zend Framework component:

Creating the Zend_Service_Mollom object

// Keys can be obtained in the Mollom site manager.
$public = 'your-public-key';
$private = 'your-private-key';
$mollom = new Zend_Service_Mollom($public, $private);

This object can then be used to check your user-submitted content:

Checking user-submitted content

$data = array('post_title'  => $_POST['comment_title'],
              'post_body'   => $_POST['comment_body'],
              'author_name' => $_POST['author_name']);
$results = $mollom->checkContent($data);

/* $results is now an array in the form of:
 * array(3) {
 *   ["quality"]=>
 *   float(0)
 *   ["session_id"]=>
 *   string(16) "aab0a316d1770d73"
 *   ["classification"]=>
 *   string(4) "spam"
 * }

As you can see, Mollom provides you with a quality ranking (zero in this case), a session id and a classification (which can be spamunsure or ham). The method uses an array parameter which can be used to supply as much info as you can. The more you supply, the better Mollom works. You can use the following fields:

  • session_id
  • post_title
  • post_body
  • author_name
  • author_url
  • author_mail
  • author_openid
  • author_ip
  • author_id

A full description of these fields is in the Mollom API documentation.

In the case of an unsure match, you should show a CAPTCHA to the user. This can be requested using the getAudioCaptcha or getImageCaptcha methods:

Requesting a CAPTCHA

$is_correct = $mollom->checkCaptcha($session_id, $solution);

There are plenty of different ways to use this component. Check the comments in the PHP file (sorry, no API doc yet) and the Mollom API documentation for more information on how to use it. Should be fairly easy.

Speeding up Zend_Service_Mollom

Optionally, you can supply Zend_Service_Mollom with a cache object, which speeds up the calls made to the Mollom service. Doing this is straightforward:

Setting up caching

$cache = ... // Check the Zend_Cache manual to make a
             // Zend_Cache_Core object

For convenience there are also the static methods getCache(), hasCache(), clearCache() and removeCache().

Question: Why not PHP Mollom?

There already is a Mollom library for PHP: PHP Mollom. However, I prefer a Zend Framework version for two reasons:

  • PHP Mollom does not integrate, nor reuse Zend Framework and therefore duplicates quite a lot of code. As such, Zend_Service_Mollom has only half as much lines of code as PHP Mollom.
  • The entire API of PHP Mollom consists of static methods. Object instances are not used. This is generally considered to be bad object-oriented design.

December 21, 2008 17:14