{"id":13580392,"url":"https://github.com/davidcole1340/ext-php-rs","last_synced_at":"2025-12-30T04:07:44.182Z","repository":{"id":37099075,"uuid":"345926044","full_name":"davidcole1340/ext-php-rs","owner":"davidcole1340","description":"Bindings for the Zend API to build PHP extensions natively in Rust.","archived":false,"fork":false,"pushed_at":"2025-05-03T15:22:39.000Z","size":37864,"stargazers_count":656,"open_issues_count":56,"forks_count":70,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-03T16:35:31.044Z","etag":null,"topics":["ffi","hacktoberfest","php","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davidcole1340.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE_APACHE","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,"zenodo":null}},"created_at":"2021-03-09T07:55:09.000Z","updated_at":"2025-04-27T01:30:21.000Z","dependencies_parsed_at":"2024-01-01T12:21:03.692Z","dependency_job_id":"c4ac15da-53a4-46d9-b3e5-f0623e51c00d","html_url":"https://github.com/davidcole1340/ext-php-rs","commit_stats":{"total_commits":464,"total_committers":28,"mean_commits":"16.571428571428573","dds":0.6336206896551724,"last_synced_commit":"0d9496b76cce8914469b60f90983283c2fdb0db0"},"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcole1340%2Fext-php-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcole1340%2Fext-php-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcole1340%2Fext-php-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davidcole1340%2Fext-php-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davidcole1340","download_url":"https://codeload.github.com/davidcole1340/ext-php-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059511,"owners_count":22007769,"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":["ffi","hacktoberfest","php","rust"],"created_at":"2024-08-01T15:01:50.490Z","updated_at":"2025-05-14T03:10:17.212Z","avatar_url":"https://github.com/davidcole1340.png","language":"Rust","funding_links":[],"categories":["Rust","Table of Contents"],"sub_categories":["Extensions"],"readme":"# ext-php-rs\n\n[![Crates.io](https://img.shields.io/crates/v/ext-php-rs)](https://lib.rs/ext-php-rs)\n[![docs.rs](https://img.shields.io/docsrs/ext-php-rs/latest)](https://docs.rs/ext-php-rs)\n[![Guide Workflow Status](https://img.shields.io/github/actions/workflow/status/davidcole1340/ext-php-rs/docs.yml?branch=master\u0026label=guide)](https://davidcole1340.github.io/ext-php-rs)\n![CI Workflow Status](https://img.shields.io/github/actions/workflow/status/davidcole1340/ext-php-rs/build.yml?branch=master)\n[![Coverage Status](https://coveralls.io/repos/github/davidcole1340/ext-php-rs/badge.svg)](https://coveralls.io/github/davidcole1340/ext-php-rs)\n[![Discord](https://img.shields.io/discord/115233111977099271)](https://discord.gg/dphp)\n\nBindings and abstractions for the Zend API to build PHP extensions natively in\nRust.\n\n- Documentation: \u003chttps://docs.rs/ext-php-rs\u003e\n- Guide: \u003chttps://davidcole1340.github.io/ext-php-rs\u003e\n\n## Example\n\nExport a simple function `function hello_world(string $name): string` to PHP:\n\n```rust\n#![cfg_attr(windows, feature(abi_vectorcall))]\n\nuse ext_php_rs::prelude::*;\n\n/// Gives you a nice greeting!\n///\n/// @param string $name Your name.\n///\n/// @return string Nice greeting!\n#[php_function]\npub fn hello_world(name: String) -\u003e String {\n    format!(\"Hello, {}!\", name)\n}\n\n// Required to register the extension with PHP.\n#[php_module]\npub fn module(module: ModuleBuilder) -\u003e ModuleBuilder {\n    module\n}\n```\n\nUse [`cargo-php`] to build IDE stubs and install the extension:\n\n```text\n$ cargo install cargo-php --locked\n  Installing cargo-php v0.1.0\n$ cargo php stubs --stdout\n  Compiling example-ext v0.1.0\n  Finished dev [unoptimized + debuginfo] target(s) in 3.57s\n\u003c?php\n\n// Stubs for example-ext\n\n/**\n * Gives you a nice greeting!\n *\n * @param string $name Your name.\n *\n * @return string Nice greeting!\n */\nfunction hello_world(string $name): string {}\n$ cargo php install --release\n  Compiling example-ext v0.1.0\n  Finished release [optimized] target(s) in 1.68s\nAre you sure you want to install the extension `example-ext`? yes\n$ php -m\n[PHP Modules]\n// ...\nexample-ext\n// ...\n```\n\nCalling the function from PHP:\n\n```php\nvar_dump(hello_world(\"David\")); // string(13) \"Hello, David!\"\n```\n\nFor more examples read the library\n[guide](https://davidcole1340.github.io/ext-php-rs).\n\n[`cargo-php`]: https://crates.io/crates/cargo-php\n\n## Features\n\n- **Easy to use:** The built-in macros can abstract away the need to interact\n  with the Zend API, such as Rust-type function parameter abstracting away\n  interacting with Zend values.\n- **Lightweight:** You don't have to use the built-in helper macros. It's\n  possible to write your own glue code around your own functions.\n- **Extensible:** Implement `IntoZval` and `FromZval` for your own custom types,\n  allowing the type to be used as function parameters and return types.\n\n## Goals\n\nOur main goal is to **make extension development easier.**\n\n- Writing extensions in C can be tedious, and with the Zend APIs limited\n  documentation can be intimidating.\n- Rust's modern language features and feature-full standard library are big\n  improvements on C.\n- Abstracting away the raw Zend APIs allows extensions to be developed faster\n  and with more confidence.\n- Abstractions also allow us to support future (and potentially past) versions\n  of PHP without significant changes to extension code.\n\n## Documentation\n\nThe library guide can be read\n[here](https://davidcole1340.github.io/ext-php-rs).\n\nThe project is documented in-line, so viewing the `cargo` documentation is the\nbest resource at the moment. This can be viewed at [docs.rs].\n\n## Requirements\n\n- Linux, macOS or Windows-based operating system.\n- PHP 8.1 or later.\n  - No support is planned for earlier versions of PHP.\n  - PHP versions, that no longer receive security updates, will no longer be\n    supported. They might still work, but no guarantees are made.\n  - See \u003chttps://www.php.net/supported-versions.php\u003e for information on PHP\n    supported versions and their end of life dates.\n- Rust.\n  - Currently, we maintain no guarantee of a MSRV, however lib.rs suggests Rust\n    1.57 at the time of writing.\n- Clang 5.0 or later.\n\n### Windows Requirements\n\n- Extensions can only be compiled for PHP installations sourced from\n  \u003chttps://windows.php.net\u003e. Support is planned for other installations\n  eventually.\n- Rust nightly is required for Windows. This is due to the [vectorcall] calling\n  convention being used by some PHP functions on Windows, which is only\n  available as a nightly unstable feature in Rust.\n- It is suggested to use the `rust-lld` linker to link your extension. The MSVC\n  linker (`link.exe`) is supported however you may run into issues if the linker\n  version is not supported by your PHP installation. You can use the `rust-lld`\n  linker by creating a `.cargo\\config.toml` file with the following content:\n  ```toml\n  # Replace target triple if you have a different architecture than x86_64\n  [target.x86_64-pc-windows-msvc]\n  linker = \"rust-lld\"\n  ```\n- The `cc` crate requires `cl.exe` to be present on your system. This is usually\n  bundled with Microsoft Visual Studio.\n- `cargo-php`'s stub generation feature does not work on Windows. Rewriting this\n  functionality to be cross-platform is on the roadmap.\n- To build the application in `DEBUG` mode on Windows,\n  you must have a `PHP SDK` built with the `DEBUG` option enabled\n  and specify the `PHP_LIB` to the folder containing the lib files.\n  For example: set `PHP_LIB=C:\\php-sdk\\php-dev\\vc16\\x64\\php-8.3.13-src\\x64\\Debug_TS`.\n\n[vectorcall]: https://docs.microsoft.com/en-us/cpp/cpp/vectorcall?view=msvc-170\n\n## Cargo Features\n\nAll features are disabled by default.\n\n- `closure` - Enables the ability to return Rust closures to PHP. Creates a new\n  class type, `RustClosure`.\n- `anyhow` - Implements `Into\u003cPhpException\u003e` for `anyhow::Error`, allowing you\n  to return anyhow results from PHP functions. Supports anyhow v1.x.\n\n## Usage\n\nCheck out one of the example projects:\n\n- [anonaddy-sequoia](https://gitlab.com/willbrowning/anonaddy-sequoia) - Sequoia\n  encryption PHP extension.\n- [opus-php](https://github.com/davidcole1340/opus-php) - Audio encoder for the\n  Opus codec in PHP.\n- [tomlrs-php](https://github.com/jphenow/tomlrs-php) - TOML data format parser.\n- [php-scrypt](https://github.com/appwrite/php-scrypt) - PHP wrapper for the\n  scrypt password hashing algorithm.\n- [fluent-php](https://github.com/Ennexa/fluent-php) - PHP wrapper for Mozilla's Project Fluent i18n library.\n- [php-rocksdb-rc](https://github.com/s00d/php-rocksdb-rc) - PHP wrapper for rocksdb library.\n\n## Contributions\n\nContributions are very much welcome. I am a novice Rust developer and any\nsuggestions are wanted and welcome. Feel free to file issues and PRs through\nGithub.\n\nContributions welcome include:\n\n- Documentation expansion (examples in particular!)\n- Safety reviews (especially if you have experience with Rust and the Zend API).\n- Bug fixes and features.\n- Feature requests.\n\nWhen contributing, please keep in mind the following:\n- Create tests if possible.\n- Update the documentation if necessary.\n  - If your change is a [braking change](https://semver.org) a migration guide MUST be included. This\n    should be placed in the `guide/src/migration-guides` directory.\n- Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). We use these to automatically generate changelogs.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n## Resources\n\n- [PHP Internals Book](https://www.phpinternalsbook.com/)\n\n## License\n\nLicensed under either of\n\n- Apache License, Version 2.0 ([LICENSE_APACHE] or\n  \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\n- MIT license ([LICENSE_MIT] or \u003chttp://opensource.org/licenses/MIT\u003e)\n\nat your option.\n\n[LICENSE_APACHE]: https://github.com/davidcole1340/ext-php-rs/blob/master/LICENSE_APACHE\n[LICENSE_MIT]: https://github.com/davidcole1340/ext-php-rs/blob/master/LICENSE_MIT\n[docs.rs]: https://docs.rs/ext-php-rs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcole1340%2Fext-php-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavidcole1340%2Fext-php-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavidcole1340%2Fext-php-rs/lists"}