Solder your Rust into PHP

This library tries to help you improve your PHP application using extensions written in Rust. It started as a fork from php-rs.

The idea is to be able to write code purely in rust, compile it using cargo and load the library direct into PHP.

Note that this is the first version of this crate and a lot of things will change. Also, I can't stress enough how unstable this crate is right now. Use it with caution.

Example:

```rust extern crate libc; extern crate solder;

use solder::; use solder::zend::; use solder::info::*;

[no_mangle]

pub extern fn phpmoduleinfo() { printtablestart(); printtablerow("A demo PHP extension written in Rust", "enabled"); printtableend(); }

[no_mangle]

pub extern fn getmodule() -> *mut zend::Module { let function = FunctionBuilder::new(cstr!("helloworld"), helloworld) .witharg(ArgInfo::new(cstr!("name"), 0, 0, 0)) .build(); ModuleBuilder::new(cstr!("helloworld"), cstr!("0.1.0-dev")) .withinfofunction(phpmoduleinfo) .withfunction(function) .build() .into_raw() }

[no_mangle]

pub extern fn helloworld(data: &ExecuteData, retval: &mut Zval) { let mut namezval = Zval::newasnull(); phpparseparameters!(&mut namezval); let name = String::tryfrom(namezval).ok().unwrap(); let hello = format!("Hello {}", name); php_return!(retval, hello); } ```

To compile it, we need to add to our .cargo/config: [build] rustflags = ["-C", "link-arg=-Wl,-undefined,dynamic_lookup"]

Then, compile the extension using cargo build and load it copying it to your PHP modules dir and modifying your php.ini.

``` $ cargo build --release && php -dextension=$(pwd)/target/debug/libhelloworld.so -a Compiling solder v0.1.0 (/src) Compiling helloworld v0.1.0 (/src/examples/helloworld) Finished dev [unoptimized + debuginfo] target(s) in 5.93s Interactive shell

php > vardump(helloworld("Bruno")); string(11) "Hello Bruno" php > ```

PHP Versions

For now, this crate only works with PHP7. During the build, it tries to get the PHP API VERSION and PHP EXTENSION BUILD from the installed PHP. But, you can compile for other versions by manually setting the envs PHPAPIVERSION and PHPEXTENSIONBUILD

If you have questions or ideas to the project. Feel free to contact me.