Akismet Problems?

written by Jan on February 22nd, 2008 @ 03:46 PM

An Openminds client recently complained about their site being slow while creating a post or adding a comment, and asked us to investigate the problem. The problem quickly pointed to the Akismet plugin they had installed on their site. Using their library (which is the one you can download here), I created a small script to see if something was wrong:


<?php
  require 'Akismet.class.php';

  $akismet = new Akismet('http://blog.defv.be' ,'57346eb0b724');
  print "Authenticated!\n";
  $akismet->setCommentAuthor("Jan De Poorter");
  $akismet->setCommentAuthorEmail("jan-for-blogging-purposes@defv.be");
  $akismet->setCommentContent("Ik vind deze site cool!");

  while (true) {
    $before = microtime(true);
    $akismet->isCommentSpam();
    print "Akismet Ping: " . (microtime(true) - $before) . "\n";
  }
?>

Which gave me the following anomaly:

Authenticated!
Akismet Ping: 0.506912946701
Akismet Ping: 0.506837129593
Akismet Ping: 0.512920856476
Akismet Ping: 30.5028369427
Akismet Ping: 30.4986889362
Akismet Ping: 0.521193027496
Akismet Ping: 30.5202748775
Akismet Ping: 0.528180837631
Akismet Ping: 30.5196199417
Akismet Ping: 30.507283926
Akismet Ping: 0.521035909653
Akismet Ping: 30.513240099

It seems some of their web servers are having some issues. While investigating it further, I found out that the used library does HTTP/1.1 requests:

 
POST /1.1/comment-check HTTP/1.1 
Host: 57346eb0b724.rest.akismet.com 
Content-Type: application/x-www-form-urlencoded; charset=utf-8 
Content-Length: 2713 
User-Agent: Akismet PHP5 Class 0.2 | Akismet/1.11

Since I’ve had previous encounters with HTTP/1.1 vs HTTP/1.0 requests in my quest for Proxy Victory, I changed the code to do a HTTP/1.0 request, with some fabulous results:


Authenticated!
Akismet Ping: 0.529227972031
Akismet Ping: 0.505887985229
Akismet Ping: 0.507663965225
Akismet Ping: 0.507257938385
Akismet Ping: 0.534005880356
Akismet Ping: 0.550770998001
Akismet Ping: 0.57452917099
Akismet Ping: 0.53076004982
Akismet Ping: 0.540998935699
Akismet Ping: 0.521380901337
Akismet Ping: 0.510479927063
Akismet Ping: 0.528470039368
Akismet Ping: 0.504570960999

So, the buggy Akismet servers act nicely with HTTP/1.0. Good! Case closed for our client. It’s strange nobody noticed this before.

For your reference I have the patch here and the class as a whole here



Comments

  • Michael Gauthier on 23 Feb 21:32

    The problem does not lie with Akismet servers, the problem lies in an incorrect implementation of HTTP/1.1 persistent connections in the Akismet class. The Akismet API servers support persistent connections for HTTP/1.1 but the class is not written to use persistent connections. Specifying a 'Connection: close' header will fix the problem for HTTP/1.1.

    This is the solution I used for the following PEAR bug in Services_Akismet: http://pear.php.net/bugs/bug.php?id=13173

    HTTP/1.0 does not support persistent connections so the problem is also fixed when you switch to HTTP/1.0.

  • Mike Brittain on 24 Feb 02:42

    So glad to see this posted. Thanks Jan and Michael for covering this issue. We had the same issue on some new development code for our site. I was convinced Akismet was throttling our requests, but the Connection: close header fixed this right up!

  • Erik Bauffman on 27 Feb 16:58

    Saved my quite the hassle, thanks jan!

  • remi on 10 Mar 20:53

    thanks man, I had the same issue, your solution worked.

    Again thanks

  • Dieter on 12 Mar 23:26

    Thanks, probably saved me quite some time in testing :)

  • dusoft on 13 Mar 11:32

    Thanks, helped me to resolve the issue with timeouting or very slow AKISMET servers.

Comments are closed

Options:

Size