🦀 RustPHP

High-performance PHP extension powered by Rust

OVERVIEW

What is RustPHP?

RustPHP is a PHP extension written in Rust that allows you to execute high-performance native Rust code inside PHP applications.

SYSTEM

Requirements


PHP 8.2+
Rust (cargo, rustc)
php-cli
php-config
php-dev
INSTALL

Install Dependencies


# Debian / Ubuntu
apt install php-dev

# Arch
pacman -S php

# Fedora
dnf install php-devel

# macOS
brew install php
BUILD

Build PHP from Source


git clone https://github.com/php/php-src.git
cd php-src

git checkout PHP-8.2

./buildconf

PREFIX="$HOME/build/php"

./configure \
  --prefix="$PREFIX" \
  --enable-debug \
  --disable-all \
  --disable-cgi

make -j "$(nproc)"
make install

Output:


PHP: $HOME/build/php/bin/php
php-config: $HOME/build/php/bin/php-config
COMPOSER

Install Package


{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/Famous-Coder36/RustPHP.git"
    }
  ],
  "require": {
    "famouscoder/rustphp": "*"
  }
}

composer require famouscoder/rustphp

cargo build --manifest-path=vendor/famouscoder/rustphp/Cargo.toml
EXAMPLE

test.php


<?php
require "vendor/autoload.php";

use RustPHP\Engine;

Engine::println("Hello from RustPHP");
RUN

Execute Extension


php -d extension=./vendor/famouscoder/rustphp/target/debug/librustphp.so test.php