PHPackages                             apollorip/bencode-torrent - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. apollorip/bencode-torrent

Abandoned → [orpheusnet/bencode-torrent](/?search=orpheusnet%2Fbencode-torrent)Library[Parsing &amp; Serialization](/categories/parsing)

apollorip/bencode-torrent
=========================

PHP Library for decoding and encoding BitTorrent BEncoded data, built for Gazelle

v1.2.0(4y ago)133382[1 issues](https://github.com/ApolloRIP/bencode-torrent/issues)UnlicensePHPPHP &gt;=7.2CI failing

Since Apr 3Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ApolloRIP/bencode-torrent)[ Packagist](https://packagist.org/packages/apollorip/bencode-torrent)[ RSS](/packages/apollorip-bencode-torrent/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (3)Versions (11)Used By (0)

BEncode Torrent
===============

[](#bencode-torrent)

[![Test](https://github.com/OPSnet/bencode-torrent/actions/workflows/test.yml/badge.svg?branch=master&event=push)](https://github.com/OPSnet/bencode-torrent/actions/workflows/test.yml)[![Packagist](https://camo.githubusercontent.com/a7047db3b150ada76c4a45ad1db1d2520380c5fda0b1e5cecaec23985c32ca70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f7270686575736e65742f62656e636f64652d746f7272656e742e737667)](https://packagist.org/packages/orpheusnet/bencode-torrent)[![Packagist PHP Version Support](https://camo.githubusercontent.com/f887257565a69860a0a3289727a1cd24063aa9279c23763ef98dc48bf1de59d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f7270686575736e65742f62656e636f64652d746f7272656e74)](https://camo.githubusercontent.com/f887257565a69860a0a3289727a1cd24063aa9279c23763ef98dc48bf1de59d2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6f7270686575736e65742f62656e636f64652d746f7272656e74)

PHP library for encoding and decoding BitTorrent BEncode data, focused around usage within [Gazelle](https://github.com/OPSnet/Gazelle).

Usage
-----

[](#usage)

`composer require orpheusnet/bencode-torrent`

```
require('vendor/autoload.php');
$bencode = new \OrpheusNET\BencodeTorrent\BencodeTorrent();
$bencode->decodeFile('path/to/file.torrent');
var_dump($bencode->getName());
var_dump($bencode->getHexInfoHash());
var_dump($bencode->getFileList());
```

See the [`BencodeTorrent`](src/BencodeTorrent.php) class for more information on the available methods. Additionally, see [`Bencode`](src/Bencode.php) for the underlying library to encode/decode BEncode data.

Description
-----------

[](#description)

BEncode is the encoding used by BitTorrent to store and transmitting loosely structured data. It supports:

- byte strings
- integers
- lists
- dictionaries (associative arrays, where keys are sorted alphabetically)

You can see more information about how these types are supported at [BitTorrentSpecification#Bencoding](https://wiki.theory.org/index.php/BitTorrentSpecification#Bencoding).

In addition to the above, torrent files are expected to be BEncoded dictionaries that contain minimally the keys **announce** (byte string) and **info** (dictionary). Within the **info** dictionary, we then expect **piece length**(integer) and **pieces** (byte string). If the torrent has only a single file, we then expect **name** (byte string) and **length** (integer), whereas for a multi-file torrent, we'll have **name** (byte string) and **files** (list) where each element is a dictionary that has the keys **length** (integer) and **path** (list of strings).

As such, this library will make some checks when loading data that these mandatory fields exist or else an Exception is raised. More information on these fields can be found at [BitTorrentSpecification#Metainfo\_File\_Structure](https://wiki.theory.org/index.php/BitTorrentSpecification#Metainfo_File_Structure).

Finally, this library is primarily aimed at being used within the [Gazelle](https://github.com/OPSnet/Gazelle) so we have some utility functions within the library that make sense there to accomplish the following things:

- Ensuring torrent files are marked as 'private'
- Setting a 'source' on torrents (to ensure unique info hash)
- Cleaning out unnecessary fields that also reveal stuff about a user (like **announce list** and **created by**)
- Generate string file lists as expected by Gazelle for display

This is based (loosely) off the code in the two separate BEncode libraries within WCD's Gazelle ([bencodetorrent.class.php](https://github.com/WhatCD/Gazelle/blob/master/classes/bencodetorrent.class.php) and [torrent.class.php](https://github.com/WhatCD/Gazelle/blob/master/classes/torrent.class.php)), but without the now unnecessary 32bit shims as well as making it a unified library used for both uploading and downloading the torrent files.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 66.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 ~137 days

Recently: every ~254 days

Total

10

Last Release

1773d ago

Major Versions

v0.11.0 → v1.0.02020-10-03

PHP version history (3 changes)v0.11.0PHP ^7

v1.0.0PHP ^7.2

v1.2.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24500510?v=4)[it is madness](/maintainers/itismadness)[@itismadness](https://github.com/itismadness)

---

Top Contributors

[![itismadness](https://avatars.githubusercontent.com/u/24500510?v=4)](https://github.com/itismadness "itismadness (2 commits)")[![ChrisOrlando](https://avatars.githubusercontent.com/u/201175?v=4)](https://github.com/ChrisOrlando "ChrisOrlando (1 commits)")

---

Tags

bencodebittorrentgazelletorrent

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/apollorip-bencode-torrent/health.svg)

```
[![Health](https://phpackages.com/badges/apollorip-bencode-torrent/health.svg)](https://phpackages.com/packages/apollorip-bencode-torrent)
```

###  Alternatives

[mck89/peast

Peast is PHP library that generates AST for JavaScript code

19037.7M41](/packages/mck89-peast)[sauladam/shipment-tracker

Parses tracking information for several carriers, like UPS, USPS, DHL and GLS by simply scraping the data. No need for any kind of API access.

9642.0k](/packages/sauladam-shipment-tracker)[jstewmc/rtf

Read and write Rich Text Format (RTF) documents with PHP

46143.1k6](/packages/jstewmc-rtf)[moonshine/layouts-field

Field for repeating groups of fields for MoonShine

107.9k](/packages/moonshine-layouts-field)[tcds-io/php-jackson

A lightweight, flexible object serializer for PHP, inspired by FasterXML/jackson

112.9k10](/packages/tcds-io-php-jackson)

PHPackages © 2026

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