Skip to content

Comment check

This is the call you will make the most. It takes a number of arguments and characteristics about the submitted content and then returns a thumbs up or thumbs down. Performance can drop dramatically if you choose to exclude data points. The more data you send Akismet about each comment, the greater the accuracy. We recommend erring on the side of including too much data.

Client->checkComment(Comment $comment): string

It is important to test Akismet with a significant amount of real, live data in order to draw any conclusions on accuracy. Akismet works by comparing content to genuine spam activity happening right now (and this is based on more than just the content itself), so artificially generating spam comments is not a viable approach.

See the Akismet API documentation for more information.


Comment $comment

The Comment providing the user message to be checked.

Return value

A CheckResult value indicating whether the given Comment is ham, spam or pervasive spam.


A comment classified as pervasive spam can be safely discarded.

The method throws a ClientException when an error occurs. The exception getMessage() usually includes some debug information, provided by the X-akismet-debug-help HTTP header, about what exactly was invalid about the call.


use yii\akismet\{Author, Client, ClientException, Comment};

try {
    $client = new Client([
        "apiKey" => "123YourAPIKey",
        "blog" => ""

    $comment = new Comment(
        new Author("", "Mozilla/5.0"),
        ["content" => "A user comment", "date" => new \DateTimeImmutable]

    $result = $client->checkComment($comment);
    print $result == CheckResult::isHam ? "The comment is ham." : "The comment is spam.";

catch (ClientException $e) {
    print "An error occurred: {$e->getMessage()}"

See the API reference of this library for detailed information about the Author and Comment classes, and their properties.