{"id":18660347,"url":"https://github.com/frederick888/php-bencode","last_synced_at":"2025-06-19T03:42:06.222Z","repository":{"id":51126318,"uuid":"42916240","full_name":"Frederick888/php-bencode","owner":"Frederick888","description":"C++ PHP extension which can boost the process of encoding and decoding of Bencode.","archived":false,"fork":false,"pushed_at":"2024-01-16T11:26:48.000Z","size":226,"stargazers_count":16,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T04:55:33.034Z","etag":null,"topics":["bencode","php-extension"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Frederick888.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-22T06:40:32.000Z","updated_at":"2023-11-07T12:40:38.000Z","dependencies_parsed_at":"2024-11-07T07:47:22.012Z","dependency_job_id":"a72b8014-463e-45b2-812a-64112e79735d","html_url":"https://github.com/Frederick888/php-bencode","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frederick888%2Fphp-bencode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frederick888%2Fphp-bencode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frederick888%2Fphp-bencode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Frederick888%2Fphp-bencode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Frederick888","download_url":"https://codeload.github.com/Frederick888/php-bencode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248476264,"owners_count":21110245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bencode","php-extension"],"created_at":"2024-11-07T07:43:23.668Z","updated_at":"2025-04-11T20:31:17.559Z","avatar_url":"https://github.com/Frederick888.png","language":"C++","readme":"Code Status\n===\nGithub Actions [![Build and Test](https://github.com/Frederick888/php-bencode/actions/workflows/php.yml/badge.svg)](https://github.com/Frederick888/php-bencode/actions/workflows/php.yml)\nGitLab CI [![GitLab CI Status](https://git.tsundere.moe/Frederick888/php-bencode/badges/master/pipeline.svg)](https://git.tsundere.moe/Frederick888/php-bencode/commits/master)\n\nIntroduction\n===\nThe `php-bencode` is a PHP extension which can boost the process of encoding and decoding of [Bencode](https://en.wikipedia.org/wiki/Bencode).\n\nInstallation\n===\n***Step 1*** Install dependencies\n```bash\n# Debian, Ubuntu (from launchpad)\napt-get install php-dev\n# Redhat, CentOS, Fedora\nyum install php-devel\n```\n\n***Step 2*** Build and install\n```bash\ngit clone https://git.tsundere.moe/Frederick888/php-bencode.git\ncd php-bencode\nphpize\n./configure --enable-bencode\nmake\nmake install\n```\n\n***Step 3*** Enable `php-bencode`\n\nAdd this to your `php.ini`:\n```ini\nextension=bencode.so\n; optional: register classes in \"bencode\" namespace\nbencode.namespace=1\n```\n\nBasic Usage\n===\n***Example 1*** Parsing a string directly\n```\nphp \u003e $bnode = bitem::parse(\"d4:key1l5:hello5:worlde4:key2i99ee\");\nphp \u003e print_r($bnode-\u003eto_meta_array());\nArray\n(\n    [_type] =\u003e bdict\n    [_length] =\u003e 34\n    [_data] =\u003e Array\n        (\n            [key1] =\u003e Array\n                (\n                    [_type] =\u003e blist\n                    [_length] =\u003e 16\n                    [_data] =\u003e Array\n                        (\n                            [0] =\u003e Array\n                                (\n                                    [_type] =\u003e bstr\n                                    [_length] =\u003e 7\n                                    [_data] =\u003e hello\n                                )\n\n                            [1] =\u003e Array\n                                (\n                                    [_type] =\u003e bstr\n                                    [_length] =\u003e 7\n                                    [_data] =\u003e world\n                                )\n\n                        )\n\n                )\n\n            [key2] =\u003e Array\n                (\n                    [_type] =\u003e bint\n                    [_length] =\u003e 4\n                    [_data] =\u003e 99\n                )\n\n        )\n\n)\nphp \u003e $bnode-\u003eset('key2', new bint(100));\nphp \u003e echo $bnode;\nd4:key1l5:hello5:worlde4:key2i100ee\n```\n***Example 2*** Loading from/saving to a file\n```\nphp \u003e $bnode = bitem::load('/path/sample.dat');\nphp \u003e var_dump($bnode-\u003esave('/path/sample_copy.dat'));\nbool(true)\nphp \u003e var_dump(md5_file('/path/sample.dat') === md5_file('/path/sample_copy.dat'));\nbool(true)\n```\n***Example 3*** Set/delete a path\n\n*it may be a better choice to use set_path/get_path/del_path instead, check phpdoc*\n```\nphp \u003e $bnode = new bdict();\nphp \u003e $bnode-\u003eset('key1', new blist());\nphp \u003e $bnode-\u003eget('key1')-\u003eadd(new bstr('hello'));\nphp \u003e $bnode-\u003eget('key1')-\u003eadd(new bstr('world'));\nphp \u003e print_r($bnode-\u003eto_array());\nArray\n(\n    [key1] =\u003e Array\n        (\n            [0] =\u003e hello\n            [1] =\u003e world\n        )\n\n)\nphp \u003e var_dump($bnode-\u003edel('key2'));        // inexistent key\nbool(false)\nphp \u003e var_dump($bnode-\u003eget('key1')-\u003edel(1));\nbool(true)\nphp \u003e print_r($bnode-\u003eto_array());\nArray\n(\n    [key1] =\u003e Array\n        (\n            [0] =\u003e hello\n        )\n\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrederick888%2Fphp-bencode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrederick888%2Fphp-bencode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrederick888%2Fphp-bencode/lists"}