Phine Solutions web work notes

Why my Akismet external client is so slow

Filed under: programming in general — 1.618 @ 9:39 am

Akismet is a great comment spam catching service provided by wordpress.com. I use an external PHP client to test the comment or contact form spam in my sites and it had been working great. Only recently, I noticed that sometimes I receive several same message from the contact form from the same user. Originally I thought it must have been some “annoying” users who sent multiple identical messages to get noticed, but when the number of cases increased, it became an issue to invest.

After some tryouts myself it turned out the submission of a contact form was painfully slow. The users must had been refreshing the page in frustration of the slow response. And the cause was the Akismet client, which took about 40-60 seconds to return. Naturally I checked the web to see if this had been an issue to this other people. Although the information was sparse, there are a couple of solutions, and both works.

1. Upgrde the Akismet client

I use PHP5 Akismet client by Alex, and sure enough there is a new version (0.4) that addresses this issue. A more detailed test by Jan De Poorter can be found here. So by changing HTTP version back to 1.0 fixed the issue.

2. Modify the HTTP request

But why the newer and better HTTP 1.1 had problem? One of the big improvement in HTTP/1.1 is the capability to handle the persistent connection. In a nutshell, a client can keep the TCP connection open in HTTP/1.1 and use the same connection for the subsequent requests to save the resource by not opening new connection each time. Sounds promising right? However, this makes the client to be responsible to close the connection since the server would not have any idea when it’s done. If a client does not wish to handle it, it must specify “Connection: close” in the http header and tells the server that this request SHOULD NOT be considered persistent after the current request/response is complete.

If you use PHP5 Akismet client and want to stick with HTTP/1.1, you can add this in the http_post function:

$http_request .= “Connection: Close\r\n”;

Which will also fix the performance problem.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

©phinesolutions.com