PHPackages                             ecourty/torrent-tracker-client - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. ecourty/torrent-tracker-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ecourty/torrent-tracker-client
==============================

A modern PHP 8.3+ library for communicating with BitTorrent trackers over HTTP (BEP 3) and UDP (BEP 15), supporting both announce and scrape operations.

1.0.0(1w ago)00MITPHPPHP &gt;=8.3CI passing

Since Mar 9Pushed 1w agoCompare

[ Source](https://github.com/EdouardCourty/torrent-tracker-client)[ Packagist](https://packagist.org/packages/ecourty/torrent-tracker-client)[ RSS](/packages/ecourty-torrent-tracker-client/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

torrent-tracker-client
======================

[](#torrent-tracker-client)

[![PHP CI](https://github.com/EdouardCourty/torrent-tracker-client/actions/workflows/ci.yml/badge.svg)](https://github.com/EdouardCourty/torrent-tracker-client/actions/workflows/ci.yml)

A modern PHP 8.3+ library for communicating with BitTorrent trackers over **HTTP** (BEP 3) and **UDP** (BEP 15), supporting both **announce** and **scrape** operations.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Basic usage](#basic-usage)
    - [Injecting a custom HTTP client](#injecting-a-custom-http-client)
    - [Direct client usage](#direct-client-usage)
- [Exceptions](#exceptions)
- [BEP references](#bep-references)

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

[](#requirements)

- PHP 8.3+
- `ext-sockets` (for UDP trackers)

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

[](#installation)

```
composer require ecourty/torrent-tracker-client
```

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

The `TrackerClient` façade auto-detects the protocol from the tracker URL (`http://`, `https://`, or `udp://`).

```
use Ecourty\TorrentTrackerClient\TrackerClient;
use Ecourty\TorrentTrackerClient\Request\AnnounceRequest;
use Ecourty\TorrentTrackerClient\Request\ScrapeRequest;
use Ecourty\TorrentTrackerClient\Enum\AnnounceEvent;

$client = new TrackerClient('udp://tracker.opentrackr.org:1337/announce');

// Announce
$response = $client->announce(new AnnounceRequest(
    infoHash: $infoHash,   // 20-byte binary string
    peerId: $peerId,       // 20-byte binary string
    port: 6881,
    uploaded: 0,
    downloaded: 0,
    left: $totalBytes,
    event: AnnounceEvent::STARTED,
));

echo $response->interval;        // re-announce interval in seconds
echo $response->seeders;         // number of seeders
echo $response->leechers;        // number of leechers
foreach ($response->peers as $peer) {
    echo $peer->ip . ':' . $peer->port . PHP_EOL;
}

// Scrape
$scrape = $client->scrape(new ScrapeRequest(infoHashes: [$infoHash]));
$stats = $scrape->torrents[bin2hex($infoHash)];
echo $stats->seeders . ' seeders, ' . $stats->completed . ' completed';
```

### Injecting a custom HTTP client

[](#injecting-a-custom-http-client)

For HTTP trackers, you can inject any `Symfony\Contracts\HttpClient\HttpClientInterface` — useful when you need a pre-configured client (proxy, retry, authentication, etc.):

```
use Symfony\Component\HttpClient\HttpClient;

$httpClient = HttpClient::create([
    'timeout' => 10,
    'proxy' => 'http://proxy.example.com:8080',
]);

$client = new TrackerClient(
    trackerUrl: 'http://tracker.example.com/announce',
    httpClient: $httpClient,
);
```

### Direct client usage

[](#direct-client-usage)

You can also instantiate `HttpTrackerClient` or `UdpTrackerClient` directly:

```
use Ecourty\TorrentTrackerClient\Client\HttpTrackerClient;
use Ecourty\TorrentTrackerClient\Client\UdpTrackerClient;

$http = new HttpTrackerClient('http://tracker.example.com/announce', timeout: 5);
$udp  = new UdpTrackerClient('udp://tracker.opentrackr.org:1337/announce', timeout: 5);
```

Exceptions
----------

[](#exceptions)

All exceptions extend `Ecourty\TorrentTrackerClient\Exception\TrackerException` (itself extending `\RuntimeException`):

ExceptionWhen`ConnectionException`Cannot connect to the tracker`TimeoutException`Request timed out`InvalidResponseException`Malformed or failure response```
use Ecourty\TorrentTrackerClient\Exception\TrackerException;

try {
    $response = $client->announce($request);
} catch (TrackerException $e) {
    echo 'Tracker error: ' . $e->getMessage();
}
```

BEP references
--------------

[](#bep-references)

- [BEP 3](https://www.bittorrent.org/beps/bep_0003.html) — HTTP tracker protocol
- [BEP 15](https://www.bittorrent.org/beps/bep_0015.html) — UDP tracker protocol
- [BEP 48](https://www.bittorrent.org/beps/bep_0048.html) — HTTP scrape convention

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance98

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

13d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3150ffb131124e5f03272d9ed8084c514f18fff6aafff1a5973c016993f6ef66?d=identicon)[ecourty](/maintainers/ecourty)

---

Top Contributors

[![EdouardCourty](https://avatars.githubusercontent.com/u/37371516?v=4)](https://github.com/EdouardCourty "EdouardCourty (6 commits)")

---

Tags

httpscrapetorrentudptrackerbittorrentannouncebep3bep15

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ecourty-torrent-tracker-client/health.svg)

```
[![Health](https://phpackages.com/badges/ecourty-torrent-tracker-client/health.svg)](https://phpackages.com/packages/ecourty-torrent-tracker-client)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k997.0M2.8k](/packages/guzzlehttp-psr7)[psr/http-message

Common interface for HTTP messages

7.1k1.0B4.9k](/packages/psr-http-message)[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k670.9k10](/packages/hhxsv5-laravel-s)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

537194.9M19](/packages/league-uri-interfaces)

PHPackages © 2026

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