PHPackages                             bencodex/bencodex - 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. bencodex/bencodex

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

bencodex/bencodex
=================

Bencodex reader/writer for PHP

0.1.0(4y ago)31.6k↓33.3%MITPHPPHP &gt;=5.4.0

Since Oct 19Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dahlia/bencodex-php)[ Packagist](https://packagist.org/packages/bencodex/bencodex)[ Docs](https://github.com/dahlia/bencodex-php)[ RSS](/packages/bencodex-bencodex/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Bencodex reader/writer for PHP
==============================

[](#bencodex-readerwriter-for-php)

[![Packagist Version](https://camo.githubusercontent.com/31282f9303e47f8070a8b4925d850d338f35b308ab458141c241730aa67d7d1c/687474703a2f2f706f7365722e707567782e6f72672f62656e636f6465782f62656e636f6465782f76)](https://packagist.org/packages/bencodex/bencodex)[![MIT License](https://camo.githubusercontent.com/d71a7c5f9d08892fed49fd18397d7981e60a0b6ffc3b6c8b3bc8728526a3add9/687474703a2f2f706f7365722e707567782e6f72672f62656e636f6465782f62656e636f6465782f6c6963656e7365)](LICENSE)[![GitHub Actions Status](https://github.com/dahlia/bencodex-php/actions/workflows/build.yaml/badge.svg)](https://github.com/dahlia/bencodex-php/actions/workflows/build.yaml)

This package implements [Bencodex](https://bencodex.org/) serialization format which extends [Bencoding](https://www.bittorrent.org/beps/bep_0003.html#bencoding). Complianet with Bencodex 1.2.

```
php > echo Bencodex\encode(['foo' => 123, 'bar' => [true, false]]);
du3:barltfeu3:fooi123ee
php > var_dump(Bencodex\decode('du3:barltfeu3:fooi123ee'));
object(stdClass)#4 (2) {
  ["bar"]=>
  array(2) {
    [0]=>
    bool(true)
    [1]=>
    bool(false)
  }
  ["foo"]=>
  int(123)
}
```

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

[](#requirements)

[![PHP Version Requirement](https://camo.githubusercontent.com/d9c6443deadd52298fdb342a4b0565f2d96d8e37ca8eeb51e87f189eb320dbc4/687474703a2f2f706f7365722e707567782e6f72672f62656e636f6465782f62656e636f6465782f726571756972652f706870)](https://packagist.org/packages/bencodex/bencodex)

- PHP 5.4 or later
- [iconv](https://www.php.net/manual/en/book.iconv.php) extension (`--with-iconv`)

Type correspondences
--------------------

[](#type-correspondences)

PHPBencodexNullNullBooleanBooleanIntegerIntegerDouble[1](#user-content-fn-1-400ee089609372e0c42d6a385e5f1860)Integer (truncated)Numeric string[2](#user-content-fn-2-400ee089609372e0c42d6a385e5f1860)Integer ≥ [`PHP_INT_MAX`](https://www.php.net/manual/en/reserved.constants.php#constant.php-int-max)String which can be decoded as UnicodeText[2](#user-content-fn-2-400ee089609372e0c42d6a385e5f1860)String otherwiseBinary[2](#user-content-fn-2-400ee089609372e0c42d6a385e5f1860)List-like array[3](#user-content-fn-3-400ee089609372e0c42d6a385e5f1860)ListMap-like array[1](#user-content-fn-1-400ee089609372e0c42d6a385e5f1860)DictionaryObjectDictionaryUsage
-----

[](#usage)

- [`\Bencodex\encode(mixed $value): string`](https://dahlia.github.io/bencodex-php/namespaces/bencodex.html#function_encode): Encodes a PHP `$value`into Bencodex data.
- [`\Bencodex\decode(string $bencodex): mixed`](https://dahlia.github.io/bencodex-php/namespaces/bencodex.html#function_decode): Decodes Bencodex data into a PHP value.

The above APIs are merely façade, and optional parameters are omitted. See the [complete API docs](https://dahlia.github.io/bencodex-php/) as well.

Footnotes
---------

1. One-way types only available for encoding. [↩](#user-content-fnref-1-400ee089609372e0c42d6a385e5f1860) [↩2](#user-content-fnref-1-2-400ee089609372e0c42d6a385e5f1860)
2. One-way types only available for decoding. [↩](#user-content-fnref-2-400ee089609372e0c42d6a385e5f1860) [↩2](#user-content-fnref-2-2-400ee089609372e0c42d6a385e5f1860) [↩3](#user-content-fnref-2-3-400ee089609372e0c42d6a385e5f1860)
3. Determined by [`array_is_list()` function](https://www.php.net/manual/en/function.array-is-list). [↩](#user-content-fnref-3-400ee089609372e0c42d6a385e5f1860)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

1672d ago

### Community

Maintainers

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

---

Top Contributors

[![dahlia](https://avatars.githubusercontent.com/u/12431?v=4)](https://github.com/dahlia "dahlia (31 commits)")

---

Tags

bencodexbencodingphpserializationserializationbencodingbencodex

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[opis/closure

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

2.6k230.0M284](/packages/opis-closure)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[google/flatbuffers

FlatBuffers for PHP

25.7k134.7k4](/packages/google-flatbuffers)[apache/avro

Apache Avro™ is a data serialization system.

3.2k26.8k3](/packages/apache-avro)[flix-tech/avro-serde-php

A library to serialize and deserialize Avro records making use of the confluent schema registry

674.0M17](/packages/flix-tech-avro-serde-php)

PHPackages © 2026

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