Crate phper[−][src]
Expand description
A library that allows us to write PHP extensions using pure Rust and using safe Rust whenever possible.
Usage
- Make sure
libclangandphpis 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 { let mut module = Module::new( env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"), env!("CARGO_PKG_AUTHORS"), ); // ... module }
- 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 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 |
Derive Macros
| Throwable | Auto derive for |