PHP Enjoy Rust

The framework that allows us to write PHP extensions using pure and safe Rust whenever possible.

CI Crates.io Docs.rs License
Get Started View on GitHub

Why PHPER?

๐Ÿฆ€

Pure Rust

Write PHP extensions in pure, safe Rust โ€” no C/C++ glue code required. Enjoy Rust's memory safety guarantees.

๐Ÿ“ฆ

Rust Ecosystem

Leverage the entire Rust crate ecosystem directly in your PHP extensions. Use reqwest, serde, tokio, and more.

๐Ÿ”ง

Full-Featured Framework

Register functions, classes, interfaces, enums, constants, INI settings and lifecycle hooks with an ergonomic API.

๐Ÿ˜

Wide PHP Support

Supports PHP 7.0 through 8.5 across Linux and macOS, covering CLI and FPM SAPIs.

โšก

Easy to Start

Create a new extension with just cargo new. Build with cargo build. No phpize needed for development.

๐Ÿงช

Integration Testing

Built-in integration test support via phper-test. Test your PHP extensions with familiar Rust test tools.

Compatibility

CategoryItemStatus
OSLinuxโœ…
macOSโœ…
PHP Version7.0 โ€“ 7.4โœ…
8.0 โ€“ 8.5โœ…
PHP ModeNTSโœ…
SAPICLIโœ…
FPMโœ…
Rust1.85+โœ…
Dependencylibclang 9.0+Required

Quick Example

A hello world PHP extension in Rust โ€” it's that simple.

use phper::{echo, functions::Argument, modules::Module, php_get_module, values::ZVal};

/// The php function, receive arguments with type `ZVal`.
fn say_hello(arguments: &mut [ZVal]) -> phper::Result<()> {
    let name = arguments[0].expect_z_str()?.to_str()?;
    echo!("Hello, {}!\n", name);
    Ok(())
}

/// This is the entry of php extension.
#[php_get_module]
pub fn get_module() -> Module {
    let mut module = Module::new(
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        env!("CARGO_PKG_AUTHORS"),
    );
    module.add_function("say_hello", say_hello)
        .argument(Argument::new("name"));
    module
}

Projects Using PHPER

apache/skywalking-php

The PHP Agent for Apache SkyWalking, which provides the native tracing abilities for PHP project.

phper-framework/jieba-php

The Jieba Chinese Word Segmentation Implemented in Rust Bound for PHP.