use OpenDAL\Operator;
$op = new Operator("fs", ["root" => "/tmp"]);
$op->write("test.txt", "hello world");
echo $op->read("test.txt"); // hello world
- PHP 8.1+
- Composer
We use ext-php-rs to build PHP extensions natively in Rust, it's different from the traditional PHP extension development and cannot be installed using pecl
or phpize
. Before installing the extension, it is necessary to install Rust and Cargo. For instructions on how to install them, please refer to Rust's website.
- Clone the repository
git clone [email protected]:apache/opendal.git
- Build the opendal-php extension
cd opendal/bindings/php
cargo build
don't forget to add
--release
flag for production use.
- Enable extension for PHP Manually
cd opendal
# 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();")
- Enable extension for PHP using cargo-php
You can also use cargo-php directly to install the extension, see cargo-php for more details.
cargo install cargo-php
cd opendal/bindings/php
cargo php install
This command will automatically build the extension and copy it to the extension directory of the current PHP version.
- Test
use php -m
to check if the extension is installed successfully.
php -m | grep opendal-php
Composer test:
cd opendal/bindings/php
composer install
composer test
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.