PHPackages                             omines/akismet - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. omines/akismet

ActiveLibrary[API Development](/categories/api)

omines/akismet
==============

Open source library for using the Wordpress Akismet anti spam service

1.0.1(1y ago)114.8k↓50%3[1 issues](https://github.com/omines/akismet/issues)[1 PRs](https://github.com/omines/akismet/pulls)MITPHPPHP &gt;=8.1CI passing

Since Apr 19Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/omines/akismet)[ Packagist](https://packagist.org/packages/omines/akismet)[ RSS](/packages/omines-akismet/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (13)Versions (10)Used By (0)

Akismet Client Library for PHP
==============================

[](#akismet-client-library-for-php)

[![Latest Stable Version](https://camo.githubusercontent.com/761be48b5310e5ea7fc7ea2f40cc29dc8907c9fe8dc5b8a1cbd87673e764e40d/68747470733a2f2f706f7365722e707567782e6f72672f6f6d696e65732f616b69736d65742f76657273696f6e)](https://packagist.org/packages/omines/akismet)[![Total Downloads](https://camo.githubusercontent.com/4f80c67b5273576f3f8b6fa03b5ed5ee680000b6341b3ecdbc8077b49e2aa64d/68747470733a2f2f706f7365722e707567782e6f72672f6f6d696e65732f616b69736d65742f646f776e6c6f616473)](https://packagist.org/packages/omines/akismet)[![Latest Unstable Version](https://camo.githubusercontent.com/e23dd94fd7f4e94c3ad20a899348b1a81d92edd953cc07ddabf73b2a0bb22600/68747470733a2f2f706f7365722e707567782e6f72672f6f6d696e65732f616b69736d65742f762f756e737461626c65)](//packagist.org/packages/omines/akismet)[![License](https://camo.githubusercontent.com/0cc811ff28d845c1e69da00b58ed5a416f35cc643d605d9e605a191333229882/68747470733a2f2f706f7365722e707567782e6f72672f6f6d696e65732f616b69736d65742f6c6963656e7365)](https://packagist.org/packages/omines/akismet)

This library provides a straightforward object oriented and pluggable implementation of the well known online Akismet spam detection service. All known features and calls are implemented.

Documentation
-------------

[](#documentation)

Install the library with Composer:

```
composer require omines/akismet
```

### Creating the service

[](#creating-the-service)

You have to bring your own HTTP client implementation, based on [Symfony Contracts](https://symfony.com/doc/current/components/contracts.html). Easiest is to install the [Symfony HTTP Client component](https://symfony.com/doc/current/http_client.html):

```
composer require symfony/http-client
```

When using the Symfony framework this will provide a configurable service you can inject where needed, otherwise you can instantiate a stock client using:

```
$httpClient = HttpClient::create();
```

Now instantiate the service class, also providing your [Akismet API key](https://akismet.com/account/) and the root URL of your site/blog:

```
$akismet = new Akismet($httpClient, 'Akismet API key', 'https://www.example.org/');
```

### Using as a Symfony service

[](#using-as-a-symfony-service)

Add the following to `config/services.yaml`, assuming autowiring is enabled as it should in Symfony:

```
    Omines\Akismet\Akismet:
        arguments:
            # Your 'blog', this should be the root URL of your deployment
            $instance: '%env(ROOT_URL)%'

            # Your Akismet API key
            $apiKey: '%env(AKISMET_KEY)%'
```

Then make sure your relevant `.env` file or the actual environment variables contain correct values for `ROOT_URL`and `AKISMET_KEY`. You can now inject `Omines\Akismet\Akismet` wherever you need it.

### Creating a message

[](#creating-a-message)

You have to construct and fill an `AkismetMessage` before you can check or submit anything:

```
$message = (new AkismetMessage())
    ->setUserIP('1.2.3.4')
    ->setType(MessageType::COMMENT)
    ->setContent('Some spammy message')
    ->setAuthorEmail('medicine_seller_1983@gmail.com')
;
```

Depending on your framework you will already have some useful data available in either a Symfony HTTP Foundation `Request`instance or a PSR-7 `ServerRequestInterface` derivant. Bootstrapping a message from these to copy the user IP, user agent and HTTP referrer fields is easy:

```
$message = AkismetMessage::fromRequest($symfonyRequest);
// or
$message = AkismetMessage::fromPSR7Request($psr7Request);
```

You can, and sometimes should, safely serialize the `AkismetMessage` class, for example when implementing moderation queues. After moderation you can unserialize the message to submit the exact message you checked before as Ham or Spam.

### Checking a message

[](#checking-a-message)

Performing a spam check is then simple:

```
$response = $akismet->check($message);
if ($response->isSpam()) {
    if ($response->shouldDiscard()) {
      // Akismet believes this to be the most pervasive and worst spam, not even worthy of moderation
    } else {
      // The message is considered spam, so it should either be refused or manually reviewed
    }
}
```

Read [their blog post](https://akismet.com/blog/theres-a-ninja-in-your-akismet/) on the 'should discard' feature.

### Asynchronous invocation

[](#asynchronous-invocation)

When using `symfony/http-client` as the HTTP client implementation all calls are asynchronous out of the box. As such, in the example above, the call to `Akismet::check` is **not** blocking further execution. This allows you to improve your site performance by continuing to do other tasks in parallel, such as preparing notification emails and such.

Execution will block when you call any informational methods on the response, in this case the `isSpam` method call.

### Submitting confirmed ham and spam

[](#submitting-confirmed-ham-and-spam)

As mentioned before, when implementing moderation you can safely serialize the `AkismetMessage` instance submitted for checking. After human review you can then help improve Akismet's services by submitting the message as ham or spam:

```
$response = $this->akismet->submitHam($message);
$response = $this->akismet->submitSpam($message);
```

The `MessageResponse` object returned by these calls can, if you want, be checked for success with `$response->isSuccessful()`, in an asynchronous method this is technically not required - the methods are fire and forget.

### Usage limit and activity

[](#usage-limit-and-activity)

You can check your usage limits and key/site activity:

```
$response = $this->akismet->usageLimit();
if ($response->getPercentage() > 50) {
    @trigger_error('Used up more than half the usage limit', E_USER_WARNING);
}
$response = $this->akismet->activity(limit: 100);
foreach ($response->getMonths() as $month => $activities) {
   // Do stuff
}
```

For the parameters and response formats of the activity call refer to [the Akismet documentation](https://akismet.com/key-sites-activity/).

Contributing
------------

[](#contributing)

Contributions are **welcome** and will be credited.

We accept contributions via Pull Requests on [Github](https://github.com/omines/akismet). Follow [good standards](http://www.phptherightway.com/), keep the [PHPStan level](https://phpstan.org/user-guide/rule-levels) maxed, and keep the test coverage at 100%.

Before committing, run `bin/prepare-commit` to automatically follow coding standards, run PHPStan and run all tests. To run the live tests create a `.env.local` defining `AKISMET_KEY`. As they run in test mode they will not interfere with your quota or get you banned.

Legal
-----

[](#legal)

This software was developed for internal use at [Omines Full Service Internetbureau](https://www.omines.nl/)in Eindhoven, the Netherlands. It is shared with the general public under the permissive MIT license, without any guarantee of fitness for any particular purpose. Refer to the included `LICENSE` file for more details.

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance60

Regular maintenance activity

Popularity30

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~137 days

Total

8

Last Release

571d ago

Major Versions

0.1.5 → 1.0.02023-05-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/b168fc74c73849308864d64557aef16f2ff683d1b43abf1fe788c44d4fd4e573?d=identicon)[curry684](/maintainers/curry684)

---

Top Contributors

[![curry684](https://avatars.githubusercontent.com/u/1455673?v=4)](https://github.com/curry684 "curry684 (26 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (3 commits)")[![garak](https://avatars.githubusercontent.com/u/179866?v=4)](https://github.com/garak "garak (1 commits)")

---

Tags

apispamAkismetantispamspamfilter

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/omines-akismet/health.svg)

```
[![Health](https://phpackages.com/badges/omines-akismet/health.svg)](https://phpackages.com/packages/omines-akismet)
```

###  Alternatives

[algolia/algoliasearch-client-php

API powering the features of Algolia.

69433.0M114](/packages/algolia-algoliasearch-client-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[temporal/sdk

Temporal SDK

4002.2M18](/packages/temporal-sdk)[cleantalk/php-antispam

PHP API for antispam service cleantalk.org. Invisible protection from spam, no captches, no puzzles, no animals and no math.

70600.8k2](/packages/cleantalk-php-antispam)[comgate/sdk

Comgate PHP SDK

13327.8k](/packages/comgate-sdk)[helgesverre/spamprotection

A Spam Protection class for use in contact forms and comment fields, uses the StopForumSpam API.

2429.9k](/packages/helgesverre-spamprotection)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
