PHPER (PHP Enjoy Rust)

CI Crates Docs Lines License

Rust ❤️ PHP

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

Requirement

Necessary

Tested Support

Usage

  1. Make sure libclang and php is installed.

    ```bash

    If you are using debian like linux system:

    sudo apt install llvm-10-dev libclang-10-dev php-cli ```

  2. Create you cargo project, suppose your application is called myapp.

    bash cargo new myapp

  3. Add the dependencies and metadata to you Cargo project.

    ```toml [lib] crate-type = ["cdylib"]

    [dependencies] phper = "" ```

  4. Add these code to main.rs.

    ```rust,no_run use phper::cmd::make;

    fn main() { make(); } ```

  5. Create the build.rs ( Adapting MacOS ).

    rust,no_run fn main() { #[cfg(target_os = "macos")] { println!("cargo:rustc-link-arg=-undefined"); println!("cargo:rustc-link-arg=dynamic_lookup"); } }

  6. Write you owned extension logic in lib.rs.

    ```rust use phper::{phpgetmodule, modules::Module};

    [phpgetmodule]

    pub fn getmodule() -> Module { let mut module = Module::new( env!("CARGOPKGNAME"), env!("CARGOPKGVERSION"), env!("CARGOPKG_AUTHORS"), );

    // ...

    module } ```

  7. Build and install, if your php isn't installed globally, you should specify the path of php-config.

    ```bash

    Optional, specify if php isn't installed globally.

    export PHP_CONFIG=

    Build libmyapp.so.

    cargo build --release

    Install to php extension path.

    cargo run --release -- install

    Or if you install php globally, you should use sudo.

    sudo ./target/release/myapp install

    ```

  8. Edit your php.ini, add the below line.

    ini extension = myapp

  9. Enjoy.

Examples

See examples.

The projects using PHPER

License

MulanPSL-2.0.