Skip to content

phper-framework/phper

Repository files navigation

PHPer

crates

A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.

Requirement

Necessary

libclang version >= 9

php version >= 7

Tested Support

os

  • linux

php

version

  • 7.0
  • 7.1
  • 7.2
  • 7.3
  • 7.4
  • 8.0

mode

  • nts

sapi

  • cli

Usage

  1. Make sure libclang and php is installed.
# If you are using debian like linux system:
sudo apt install libclang-10-dev php-cli
  1. Create you cargo project, suppose your application is called myapp.
cargo new myapp
  1. Add the dependencies and metadata to you Cargo project.
[lib]
crate-type = ["cdylib"]

[dependencies]
phper = "0.2"
  1. Add these code to main.rs.
use phper::cmd::make;

fn main() {
    make();
}
  1. Write you owned extension logic in lib.rs.
use phper::{php_get_module, modules::Module};

#[php_get_module]
pub fn get_module(module: &mut Module) {
    // set module metadata
    module.set_name(env!("CARGO_PKG_NAME"));
    module.set_version(env!("CARGO_PKG_VERSION"));
    module.set_author(env!("CARGO_PKG_AUTHORS"));

    // ...
}
  1. Build and install, if your php isn't installed globally, you should specify the path of php-config.
# Specify if php isn't installed globally.
export PHP_CONFIG = <Your path of php-config>

# Build libmyapp.so.
cargo build --release

# Install to php extension path, if you install php globally, you should use sudo.
cargo run --release -- install
  1. Edit your php.ini, add the below line.
extension = myapp
  1. Enjoy.

examples

See examples.

License

Unlicense.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 9