All Projects → Frederick888 → php-bencode

Frederick888 / php-bencode

Licence: GPL-3.0 license
C++ PHP extension which can boost the process of encoding and decoding of Bencode.

Programming Languages

C++
36643 projects - #6 most used programming language
PHP
23972 projects - #3 most used programming language
c
50402 projects - #5 most used programming language
M4
1887 projects

Projects that are alternatives of or similar to php-bencode

Php Ion
Asynchronous PHP
Stars: ✭ 65 (+306.25%)
Mutual labels:  php-extension
Php Akm
Ahocorasick keyword match.
Stars: ✭ 116 (+625%)
Mutual labels:  php-extension
Pht
A new threading extension for PHP
Stars: ✭ 175 (+993.75%)
Mutual labels:  php-extension
Php Rs
A library to build PHP extensions in Rust.
Stars: ✭ 81 (+406.25%)
Mutual labels:  php-extension
Ext Collections
Array manipulation extension for PHP.
Stars: ✭ 94 (+487.5%)
Mutual labels:  php-extension
V8js
V8 Javascript Engine for PHP — This PHP extension embeds the Google V8 Javascript Engine
Stars: ✭ 1,659 (+10268.75%)
Mutual labels:  php-extension
Phptdlib
PHP Extension for tdlib/td written with PHP-CPP
Stars: ✭ 59 (+268.75%)
Mutual labels:  php-extension
xray
X-Ray - PHP Engine compiler hook API (new)
Stars: ✭ 19 (+18.75%)
Mutual labels:  php-extension
Msphpsql
Microsoft Drivers for PHP for SQL Server
Stars: ✭ 1,570 (+9712.5%)
Mutual labels:  php-extension
Ycdatabase
The lightest php database framework written in c language, built in php extension, for mysql
Stars: ✭ 130 (+712.5%)
Mutual labels:  php-extension
Ant php extension
PHP 扩展, 用于 PHP-FPM、FastCGI、LD_PRELOAD等模式下突破 disabled_functions
Stars: ✭ 85 (+431.25%)
Mutual labels:  php-extension
Ip2region
Ip2region is a offline IP location library with accuracy rate of 99.9% and 0.0x millseconds searching performance. DB file is ONLY a few megabytes with all IP address stored. binding for Java,PHP,C,Python,Nodejs,Golang,C#,lua. Binary,B-tree,Memory searching algorithm
Stars: ✭ 9,836 (+61375%)
Mutual labels:  php-extension
Cphalcon
High performance, full-stack PHP framework delivered as a C extension.
Stars: ✭ 10,534 (+65737.5%)
Mutual labels:  php-extension
Gutenberg Parser Rs
An experimental Rust parser for WordPress Gutenberg post format
Stars: ✭ 76 (+375%)
Mutual labels:  php-extension
Php Psr
PHP extension providing the accepted PSR interfaces
Stars: ✭ 189 (+1081.25%)
Mutual labels:  php-extension
Seaslog
An effective,fast,stable log extension for PHP.http://pecl.php.net/package/SeasLog http://php.net/SeasLog
Stars: ✭ 1,136 (+7000%)
Mutual labels:  php-extension
Php Rdkafka
Production-ready, stable Kafka client for PHP
Stars: ✭ 1,703 (+10543.75%)
Mutual labels:  php-extension
nanobox-engine-php
Engine for running PHP apps on Nanobox
Stars: ✭ 20 (+25%)
Mutual labels:  php-extension
Php V8
PHP extension for V8 JavaScript engine
Stars: ✭ 197 (+1131.25%)
Mutual labels:  php-extension
Php Zephir Parser
The Zephir Parser delivered as a C extension for the PHP language.
Stars: ✭ 129 (+706.25%)
Mutual labels:  php-extension

Code Status

Github Actions Build and Test GitLab CI GitLab CI Status

Introduction

The php-bencode is a PHP extension which can boost the process of encoding and decoding of Bencode.

Installation

Step 1 Install dependencies

# Debian, Ubuntu (from launchpad)
apt-get install php-dev
# Redhat, CentOS, Fedora
yum install php-devel

Step 2 Build and install

git clone https://git.tsundere.moe/Frederick888/php-bencode.git
cd php-bencode
phpize
./configure --enable-bencode
make
make install

Step 3 Enable php-bencode

Add this to your php.ini:

extension=bencode.so
; optional: register classes in "bencode" namespace
bencode.namespace=1

Basic Usage

Example 1 Parsing a string directly

php > $bnode = bitem::parse("d4:key1l5:hello5:worlde4:key2i99ee");
php > print_r($bnode->to_meta_array());
Array
(
    [_type] => bdict
    [_length] => 34
    [_data] => Array
        (
            [key1] => Array
                (
                    [_type] => blist
                    [_length] => 16
                    [_data] => Array
                        (
                            [0] => Array
                                (
                                    [_type] => bstr
                                    [_length] => 7
                                    [_data] => hello
                                )

                            [1] => Array
                                (
                                    [_type] => bstr
                                    [_length] => 7
                                    [_data] => world
                                )

                        )

                )

            [key2] => Array
                (
                    [_type] => bint
                    [_length] => 4
                    [_data] => 99
                )

        )

)
php > $bnode->set('key2', new bint(100));
php > echo $bnode;
d4:key1l5:hello5:worlde4:key2i100ee

Example 2 Loading from/saving to a file

php > $bnode = bitem::load('/path/sample.dat');
php > var_dump($bnode->save('/path/sample_copy.dat'));
bool(true)
php > var_dump(md5_file('/path/sample.dat') === md5_file('/path/sample_copy.dat'));
bool(true)

Example 3 Set/delete a path

it may be a better choice to use set_path/get_path/del_path instead, check phpdoc

php > $bnode = new bdict();
php > $bnode->set('key1', new blist());
php > $bnode->get('key1')->add(new bstr('hello'));
php > $bnode->get('key1')->add(new bstr('world'));
php > print_r($bnode->to_array());
Array
(
    [key1] => Array
        (
            [0] => hello
            [1] => world
        )

)
php > var_dump($bnode->del('key2'));        // inexistent key
bool(false)
php > var_dump($bnode->get('key1')->del(1));
bool(true)
php > print_r($bnode->to_array());
Array
(
    [key1] => Array
        (
            [0] => hello
        )

)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].