Skip to content
Runnable examples to learn how PHP FFI works
Rust PHP C
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
101-hello-world
102-hello-world-with-load
103-hello-world-with-trycatch Initial commit Nov 14, 2019
201-rusty-hello-world
.gitignore
LICENSE.md
README.md

README.md

PHP FFI Examples

FFI is a new feature that ships with PHP 7.4. Previously FFI for PHP was available as a standalone extension, but it has now been included in the main PHP installation.

This repository has examples for various PHP FFI use cases, along with some Rust examples that display how to create PHP FFI compatible C-ABI libraries for PHP usage.

The examples are tied to a blog series which I am writing, and the examples are split into sections that resemble the blog series.

Requirements

All code should be runnable without adjustments, assuming you have the following prerequisites installed:

  • PHP 7.4 with FFI enabled,
  • Stable toolchain rustc/Cargo for compiling Rust libraries, the examples make use of Cargo, but you can use rustc if you know how to use it.

All examples are accompanied with a short guide on how to run or compile them.

The code has been written and tested on Linux Ubuntu, so you may have to make slight adjustments to make them work in other environments properly.

Each example in this repository is a standalone "project", meaning they run independently from each other.

Licensing, modifying, and redistributing

All code provided in this repository is MIT licensed. These examples are meant to be used as a reference or a starting point for real applications. There is no real value in using the example code "as is", though I am not stopping you from doing that.

You can’t perform that action at this time.