Skip to main content

Apache OpenDAL™ PHP Binding

A PHP extension for OpenDAL: access S3, GCS, Azure Blob, the local filesystem, and 50+ more services through one synchronous API, with the performance of the Rust core underneath.

New to the model behind the API? Read Concepts first — service, operator, layer, and operation are the same four ideas in every language.

Status

Experimental / work in progress. The binding is unreleased and has no published package. It is built from source as a native PHP extension using ext-php-rs. The API may change without notice. It is not ready for production use.

Capabilities

  • Synchronous API — all calls block; there is no async variant.
  • String and binary writeswrite for UTF-8 strings, write_binary for arbitrary byte arrays.
  • Metadatastat returns content length, content type, ETag, MD5, and entry mode (file or directory).
  • Directory operationscreate_dir creates directories recursively.
  • All services that OpenDAL supports are available as long as they are enabled at compile time; see Services.

Building and installing the extension

The extension cannot be installed with pecl or through Composer. You must build it from the repository source.

Requirements

Step 1 — Clone the repository

git clone https://github.com/apache/opendal.git

Step 2 — Build the extension

cd opendal/bindings/php
cargo build

Add --release for production builds.

Step 3 — Enable the extension

Copy the compiled library to PHP's extension directory and add the extension= directive to php.ini:

# Linux
cp target/debug/libopendal_php.so $(php -r "echo ini_get('extension_dir');")/libopendal_php.so
echo "extension=libopendal_php.so" >> $(php -r "echo php_ini_loaded_file();")

# macOS
cp target/debug/libopendal_php.dylib $(php -r "echo ini_get('extension_dir');")/libopendal_php.dylib
echo "extension=libopendal_php.dylib" >> $(php -r "echo php_ini_loaded_file();")

# Windows
cp target/debug/libopendal_php.dll $(php -r "echo ini_get('extension_dir');")/libopendal_php.dll
echo "extension=libopendal_php.dll" >> $(php -r "echo php_ini_loaded_file();")

Alternatively, use cargo-php to build and install in one step:

cargo install cargo-php
cd opendal/bindings/php
cargo php install

Verify the installation

php -m | grep opendal-php

Next steps

  1. Getting started — construct an operator, then write, read, inspect, and delete a file.