PHPackages                             spamtroll/php-sdk - 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. spamtroll/php-sdk

ActiveLibrary[API Development](/categories/api)

spamtroll/php-sdk
=================

PHP SDK for the Spamtroll spam detection API.

v0.9.3(2mo ago)0219—0%MITPHP &gt;=8.0

Since Apr 24Compare

[ Source](https://github.com/spamtroll/spamtroll-php-sdk)[ Packagist](https://packagist.org/packages/spamtroll/php-sdk)[ Docs](https://spamtroll.io)[ RSS](/packages/spamtroll-php-sdk/feed)WikiDiscussions Synced 3w ago

READMEChangelogDependencies (8)Versions (5)Used By (0)

Spamtroll PHP SDK
=================

[](#spamtroll-php-sdk)

[![Latest Version](https://camo.githubusercontent.com/67e9ae084a9c9310705337d4a05ca483c72927747efa6abb727f8832b0fa98ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370616d74726f6c6c2f7068702d73646b2e737667)](https://packagist.org/packages/spamtroll/php-sdk)[![PHP Version](https://camo.githubusercontent.com/923151f7ecbf07d9a6e895f9a0cfe7de4791aba7dc17196a6fd3667c3bc031a1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7370616d74726f6c6c2f7068702d73646b2e737667)](https://packagist.org/packages/spamtroll/php-sdk)[![CI](https://github.com/spamtroll/spamtroll-php-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/spamtroll/spamtroll-php-sdk/actions/workflows/ci.yml)[![License](https://camo.githubusercontent.com/d521288cb9b9fb594a74f183db2d136a93e92783b5a244cb2234a1121da6a477/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7370616d74726f6c6c2f7068702d73646b2e737667)](LICENSE)

Zero-dependency PHP client for the [Spamtroll](https://spamtroll.io) spam detection API.

Drop it into a WordPress plugin, an IPS Community Suite application, a framework app, or a plain PHP script — the core SDK has no runtime dependencies beyond `ext-curl` and `ext-json`. Host platforms can swap in their own HTTP transport (so WP calls go through `wp_remote_*` and respect admin filters, IPS calls go through `\IPS\Http\Url`) by implementing one interface.

Requirements
------------

[](#requirements)

- PHP 8.0 or newer
- `ext-curl`, `ext-json`

Installation
------------

[](#installation)

```
composer require spamtroll/php-sdk
```

Without Composer (e.g. a bundled plugin), drop `src/` somewhere in your project and include the fallback autoloader:

```
require_once __DIR__ . '/path/to/spamtroll-php-sdk/autoload.php';
```

Quick start
-----------

[](#quick-start)

```
use Spamtroll\Sdk\Client;
use Spamtroll\Sdk\Request\CheckSpamRequest;

$client = new Client('your-api-key');

$response = $client->checkSpam(
    new CheckSpamRequest(
        content: $comment,
        source: CheckSpamRequest::SOURCE_COMMENT,
        ipAddress: $_SERVER['REMOTE_ADDR'] ?? null,
        username: $author,
        email: $authorEmail,
    )
);

if ($response->isSpam()) {
    // block
} elseif ($response->getSpamScore() >= 0.4) {
    // moderate
}
```

Configuration
-------------

[](#configuration)

```
use Spamtroll\Sdk\Client;
use Spamtroll\Sdk\ClientConfig;

$config = new ClientConfig(
    baseUrl: 'https://api.spamtroll.io/api/v1',
    timeout: 5,
    maxRetries: 3,
    retryBaseDelayMs: 500,
    userAgent: 'my-plugin/1.0 spamtroll-php-sdk/' . \Spamtroll\Sdk\Version::VERSION,
    scoreDenominator: 30.0,
);

$client = new Client('your-api-key', $config);
```

### What the fields mean

[](#what-the-fields-mean)

FieldDefaultNotes`baseUrl``https://api.spamtroll.io/api/v1`Trailing slash stripped.`timeout``5`Per-request seconds (connect + read).`maxRetries``3`Total attempts, not retries. First attempt counts.`retryBaseDelayMs``500`Backoff: `attempt * base` ms before attempt 2+. Set `0` to disable (tests).`userAgent``spamtroll-php-sdk/{version}`Host integrations should prepend their own identifier.`scoreDenominator``30.0`Maps raw API score (0…∞) to normalized 0.0–1.0 via `min(1, raw / denominator)`.Score normalization
-------------------

[](#score-normalization)

The backend scores on an open-ended additive scale. A raw score of **15** is "definitely spam", **30** is "twice the spam threshold". The SDK normalizes via `min(1.0, raw / scoreDenominator)`:

RawNormalized (denominator 30)00.007.50.25150.5022.50.7530+1.00Use `getSpamScore()` for the 0–1 value and `getRawSpamScore()` for the raw number if you need to display the native scale.

Custom HTTP adapter
-------------------

[](#custom-http-adapter)

```
use Spamtroll\Sdk\Client;
use Spamtroll\Sdk\Http\HttpClientInterface;
use Spamtroll\Sdk\Http\HttpResponse;
use Spamtroll\Sdk\Exception\ConnectionException;
use Spamtroll\Sdk\Exception\TimeoutException;

final class MyHttpClient implements HttpClientInterface
{
    public function send(string $method, string $url, array $headers, ?string $body, int $timeout): HttpResponse
    {
        // Translate connection/timeout failures into
        // ConnectionException / TimeoutException.
        // 4xx/5xx are NOT errors here — return them via HttpResponse.
    }
}

$client = new Client('your-api-key', null, new MyHttpClient());
```

WordPress and IPS integrations ship adapters that delegate to `wp_remote_*` and `\IPS\Http\Url` respectively, so platform-level filters (proxy, SSL overrides, request inspection) still apply.

Error handling
--------------

[](#error-handling)

The SDK throws when something prevents a meaningful response:

ExceptionWhen`NotConfiguredException`Empty API key.`AuthenticationException`HTTP 401 — invalid API key.`ConnectionException`Connection failure after all retries.`TimeoutException`Timeout after all retries (extends `ConnectionException`).`ServerException`HTTP 5xx after all retries.`SpamtrollException`Base for all SDK exceptions. Catch this if you want a single fail-open path.Non-fatal error responses — HTTP 429, other 4xx — are returned as a `Response` with `success === false` and an `error` message, so the caller can decide whether to back off or log.

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

[](#documentation)

- [Installation](docs/INSTALLATION.md) — requirements, Composer + manual install.
- [Usage](docs/USAGE.md) — every Client method, request fields, examples.
- [Configuration](docs/CONFIGURATION.md) — `ClientConfig` field-by-field, environment-specific recommendations.
- [HTTP adapters](docs/HTTP_ADAPTERS.md) — interface contract, reference adapters for WordPress / IPS / Guzzle.
- [Error handling](docs/ERROR_HANDLING.md) — exception hierarchy, fail-open patterns.
- [Response schema](docs/RESPONSE_SCHEMA.md) — `CheckSpamResponse` getters, score normalisation, envelope handling.
- [Contributing](docs/CONTRIBUTING.md) — local setup, quality gate, release checklist.

Development
-----------

[](#development)

```
composer install
composer qa            # cs-fixer + phpstan + peck + pest
composer test          # tests only
composer test:coverage # tests with coverage
composer lint:fix      # auto-format
```

See [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md) for the full quality gate, including the `aspell` dependency required by `composer peck`.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance82

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

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 ~0 days

Total

4

Last Release

89d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/261591664?v=4)[spamtroll](/maintainers/spamtroll)[@spamtroll](https://github.com/spamtroll)

---

Tags

apisdkspamanti-spamspamtroll

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/spamtroll-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/spamtroll-php-sdk/health.svg)](https://phpackages.com/packages/spamtroll-php-sdk)
```

###  Alternatives

[cleantalk/php-antispam

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

74613.8k2](/packages/cleantalk-php-antispam)[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

46688.8k5](/packages/deepseek-php-deepseek-php-client)[jstolpe/instagram-graph-api-php-sdk

Instagram Graph API PHP SDK

138110.7k2](/packages/jstolpe-instagram-graph-api-php-sdk)[helgesverre/spamprotection

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

2431.3k](/packages/helgesverre-spamprotection)

PHPackages © 2026

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