PHPER (PHP Enjoy Rust)
Rust ❤️ PHP
A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.
Requirement
Necessary
- rust 1.56 or later
- libclang 9.0 or later
- php 7.0 or later
Tested Support
- OS
- linux
- macos
- windows
- PHP
- version
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- mode
- nts
- zts
- sapi
- cli
- fpm
- debug
- disable
- enable
- version
Usage
-
Make sure
libclang
andphp
is installed.# If you are using debian like linux system:
-
Create you cargo project, suppose your application is called myapp.
-
Add the dependencies and metadata to you Cargo project.
[] = ["cdylib"] [] = "<LATEST VERSION>"
-
Add these code to
main.rs
.use make;
-
Write you owned extension logic in
lib.rs
.use ;
-
Build and install, if your php isn't installed globally, you should specify the path of
php-config
.# Optional, specify if php isn't installed globally. # export PHP_CONFIG=<Your path of php-config> # Build libmyapp.so. # Install to php extension path. # Or if you install php globally, you should use sudo. # sudo ./target/release/myapp install
-
Edit your
php.ini
, add the below line.extension = myapp
-
Enjoy.
Examples
See examples.