Rust library integrated into a PHP extension
C Rust
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Rust and PHP Extension Example

Docker Setup

There is a docker container that is fully setup here:

To see this in action, simply run: docker run -it -v $(pwd):/source hjr3/rust-php-ext php -d extension=/source/php-ext/modules/ -r "var_dump(score('vim', 'vi'));"

Manual Setup


To build the Rust library:

$ cd rust
$ cargo build


To build the PHP extension:

$ cd php-ext
$ phpize
$ ./configure --with-score=../rust/target/debug
$ make

You can optionally make install if you want to install the PHP extension shared object.

There are other ways to configure the PHP extension. My blog post has more details.

Run Example

Once the Rust library is built and the PHP extension is compiled, you can see it in action using:

$ php -d extension=php-ext/modules/ -r "var_dump(score('vim', 'vi'));"

The -d option tells PHP that we are passing an ini option to look for the shared object at the specified path. The -r option tells PHP to run the code within quotes.