php-bencode is a PHP Bencode extension which supports encoding, decoding, and editing Bencode strings or files. The previous version of php-bencode, which supports PHP 5, needs PHP-CPP to run while the new one now requires no external libraries.
The location of the source code remains the same, on both GitHub and my personal GitLab instance:
https://github.com/Frederick888/php-bencode
https://git.tsundere.moe/Frederick888/php-bencode
Written in C/C++, php-bencode offers a great performance boost for Bencode manipulations. I did a benchmark on different implementations by decoding a Bencode file with 1M sub-nodes in my box (8 cores, 1G memory). The sample file can be downloaded here: Bencode Sample.
According to the results, php-bencode was able to finish decoding in a significantly shorter time. The memory usage was a little higher than that of the pure PHP library, but I reckon it’s an acceptable trade-off for type safety. (For example, if the original Bencode file contains an empty dictionary or list, data loss may happen after decoding and re-encoding using the pure PHP library.)
Still, there’s much work to do. The previous version supported getting/setting a node by path and searching through the whole tree, which have not been implemented in the new one yet. Additionally, the new php-bencode supports only PHP 7 for now and I’m considering to support PHP 5.6 as well.
続きを読む
