Crate phper[][src]

Expand description

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

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 {
    let mut module = Module::new(
        env!("CARGO_PKG_NAME"),
        env!("CARGO_PKG_VERSION"),
        env!("CARGO_PKG_AUTHORS"),
    );

    // ...

    module
}
  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.

Re-exports

pub use crate::errors::Error;
pub use crate::errors::Result;
pub use phper_alloc as alloc;
pub use phper_sys as sys;

Modules

arrays

Apis relate to crate::sys::zend_array.

classes

Apis relate to crate::sys::zend_class_entry.

cmd

Command tools for build, test and install extension process.

errors

The errors for crate and php.

functions

Apis relate to crate::sys::zend_function_entry.

ini

Apis relate to crate::sys::zend_ini_entry_def.

modules

Apis relate to crate::sys::zend_module_entry.

objects

Apis relate to crate::sys::zend_object.

output

Logs and echo facilities.

strings

Apis relate to crate::sys::zend_string.

types

Apis relate to PHP types.

values

Apis relate to crate::sys::zval.

Macros

c_str

C style string end with ‘\0’.

c_str_ptr

C style string end with ‘\0’.

deprecated

PHP deprecated logging.

echo

PHP echo.

error

PHP error logging, will exit the request.

notice

PHP notice logging.

warning

PHP warning logging.

Attribute Macros

php_get_module

PHP module entry, wrap the phper::modules::Module write operation.

Derive Macros

Throwable

Auto derive for phper::errors::Throwable.