{"id":20594910,"url":"https://github.com/thomas-0816/php-go-integration","last_synced_at":"2025-09-26T07:31:10.179Z","repository":{"id":162095482,"uuid":"292338791","full_name":"thbley/php-go-integration","owner":"thbley","description":"PHP example to integrate Go using PHP-FFI","archived":false,"fork":false,"pushed_at":"2021-07-30T21:45:36.000Z","size":2125,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-11-16T08:11:42.540Z","etag":null,"topics":["go","golang","php-ffi"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thbley.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":"2020-09-02T16:41:40.000Z","updated_at":"2024-10-23T20:20:52.000Z","dependencies_parsed_at":"2023-06-18T01:16:06.897Z","dependency_job_id":null,"html_url":"https://github.com/thbley/php-go-integration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbley%2Fphp-go-integration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbley%2Fphp-go-integration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbley%2Fphp-go-integration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thbley%2Fphp-go-integration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thbley","download_url":"https://codeload.github.com/thbley/php-go-integration/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234296353,"owners_count":18809988,"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":["go","golang","php-ffi"],"created_at":"2024-11-16T08:10:48.266Z","updated_at":"2025-09-26T07:31:08.651Z","avatar_url":"https://github.com/thbley.png","language":"PHP","readme":"PHP example to integrate Go using PHP-FFI\n------------------------------------------\n\nGo is a statically typed, compiled programming language that offers more performance and concurrency.\nCombining PHP and Go gives a lot of new opportunities.\n\nWriting and integrating PHP extensions based on C/C++ can be difficult and time consuming.\nThis can be made easier and more flexible using Go libraries and PHP-FFI.\n\nGo code can compiled as a shared object file (.so) and loaded in PHP using PHP-FFI\n(see https://www.php.net/manual/en/book.ffi.php).\n\nThis example compares the performance of PHP and Go using implementations\nof the recursive ackermann function (see https://en.wikipedia.org/wiki/Ackermann_function).\n\nIn this example Go 1.14 is\n- 27 times faster than PHP 7.4 with OpCache disabled\n- 9 times faster than PHP 7.4 with Opcache enabled\n- 5 times faster than PHP 8.0 with OpCache and JIT enabled\n\nUsage:\n\n    go build -o ackermann.so -buildmode=c-shared ackermann.go\n\n    php -dopcache.enable_cli=1 -dffi.enable=1 ackermann.php\n\n    or:\n\n    docker build -t php-ffi .\n    docker run -it --rm -v $(pwd):/code php-ffi php /code/ackermann.php\n\nExample output (php7.4 -dopcache.enable_cli=0 -dffi.enable=1 ackermann.php):\n\n    PHP\n    - result: 16381\n    - time: 13.0677s\n    Go\n    - result: 16381\n    - time: 0.4877s\n    Go (using json as input/output)\n    - result: 16381\n    - time: 0.4826s\n\nExample output (php7.4 -dopcache.enable_cli=1 -dffi.enable=1 ackermann.php):\n\n    PHP\n    - result: 16381\n    - time: 4.3119s\n    Go\n    - result: 16381\n    - time: 0.4876s\n    Go (using json as input/output)\n    - result: 16381\n    - time: 0.4840s\n\nExample output (php8.0 -dopcache.enable=1 -dopcache.enable_cli=1 -dopcache.jit=1205 -dopcache.jit_buffer_size=64M -dffi.enable=1 ackermann.php):\n\n    PHP\n    - result: 16381\n    - time: 2.5359s\n    Go\n    - result: 16381\n    - time: 0.4857s\n    Go (using json as input/output)\n    - result: 16381\n    - time: 0.4825s\n\nRequirements:\n\n    Go package (https://golang.org/dl/)\n    PHP 7.4+ with FFI extension enabled\n\nNotes:\n\nPHP-FFI can automatically convert basic Go types (long, char*) into PHP types.\nFor using more complex data structures, I'm also providing an example (ackermann_json())\nusing JSON strings as input and output.\n\nReferences\n\n- https://www.php.net/manual/en/book.ffi.php\n- http://snowsyn.net/2016/09/11/creating-shared-libraries-in-go/\n- https://blog.claudiupersoiu.ro/2019/12/23/a-bit-of-php-go-ffi-and-holiday-spirit/lang/en/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomas-0816%2Fphp-go-integration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthomas-0816%2Fphp-go-integration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthomas-0816%2Fphp-go-integration/lists"}