The framework that allows us to write PHP extensions using pure and safe Rust whenever possible.
Make sure libclang
and php
is installed.
```bash
sudo apt install llvm-10-dev libclang-10-dev php-cli ```
Create you cargo project, suppose your application is called myapp.
bash
cargo new myapp
Add the dependencies and metadata to you Cargo project.
```toml [lib] crate-type = ["cdylib"]
[dependencies]
phper = "
Add these code to main.rs
.
```rust,no_run use phper::cmd::make;
fn main() { make(); } ```
Write you owned extension logic in lib.rs
.
```rust use phper::{phpgetmodule, modules::Module};
pub fn getmodule() -> Module { let mut module = Module::new( env!("CARGOPKGNAME"), env!("CARGOPKGVERSION"), env!("CARGOPKG_AUTHORS"), );
// ...
module } ```
Build and install, if your php isn't installed globally, you should specify the path of php-config
.
```bash
cargo build --release
cargo run --release -- install
```
Edit your php.ini
, add the below line.
ini
extension = myapp
Enjoy.
See examples.