Crate phper[−][src]
PHPer
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
- Make sure
libclang
andphp
is installed.
# If you are using debian like linux system:
sudo apt install libclang-10-dev php-cli
- Create you cargo project, suppose your application is called myapp.
cargo new myapp
- Add the dependencies and metadata to you Cargo project.
[lib]
crate-type = ["cdylib"]
[dependencies]
phper = "0.2"
- Add these code to
main.rs
.
use phper::cmd::make; fn main() { make(); }
- 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")); // ... }
- 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
- Edit your
php.ini
, add the below line.
extension = myapp
- Enjoy.
examples
See examples.
License
Re-exports
pub use phper_alloc as alloc; |
pub use phper_sys as sys; |
Modules
arrays | |
classes | |
cmd | |
functions | |
ini | |
logs | |
modules | |
strings | |
values |
Macros
c_str | |
c_str_ptr |
Enums
Error |
Traits
Throwable |
Type Definitions
Result |
Attribute Macros
php_get_module |