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)143342[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 today

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 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity20

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

1722d 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://www.gravatar.com/avatar/ae8d27bd414fba4f47987a3d49566f4a5e74d147484d464ae9edd599005ad734?d=identicon)[itismadness](/maintainers/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

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M284](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[michelf/php-markdown

PHP Markdown

3.5k52.4M344](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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