A new PHP extension for Bencode

It's only fair to share...Tweet about this on TwitterShare on Google+Share on FacebookShare on TumblrEmail this to someone

The source is now being hosted at both GitHub and my personal TsundereGit.
https://github.com/Frederick888/php-bencode
https://git.tsundere.moe/Frederick888/php-bencode

From Wikipedia
Bencode is the encoding used by the peer-to-peer file sharing system BitTorrent for storing and transmitting loosely structured data.

Apart from the “torrent” files, it is also used to store local data in some BitTorrent clients instead of other lightweight databases such as SQLite. However, if one gets hundreds of torrents, decoding the file would be extremely slow by some pure PHP libraries. This is why I decided to implement a PHP extension to boost the process.

There is an existed extension on Google Code, which you can also find an exportation to GitHub with some patches. But it seems that it can only parse a Bencode into plain array or convert an array back which may cause data loss during the conversion, e.g. empty arrays or lists.

Bencode should be handled by objects. But I can hardly find any introductions about handling objects in a PHP extension (reading the header file may be a better choice but it may cost a little long). Then I found PHP-CPP, which is quite friendly to new PHP extension developers. It’s a pity that it cannot be packed as a PECL package but it would be easy to build a binary package instead.

The development is not finished yet and I’m considering adding more useful features. Also, there may be lots of redundant codes to clean up 😉

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です