You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2025/05/23 12:20:33 UTC
(opendal) 01/01: refactor: Fix build failure for php binding
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch fix-php
in repository https://gitbox.apache.org/repos/asf/opendal.git
commit 587bc715d8419401b611528542804ba71e503783
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Fri May 23 20:20:09 2025 +0800
refactor: Fix build failure for php binding
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
bindings/php/Cargo.toml | 2 ++
bindings/php/src/lib.rs | 16 ++++++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/bindings/php/Cargo.toml b/bindings/php/Cargo.toml
index 6f6e74df3..2b5cf852f 100644
--- a/bindings/php/Cargo.toml
+++ b/bindings/php/Cargo.toml
@@ -33,6 +33,7 @@ crate-type = ["cdylib"]
ext-php-rs = "0.13.1"
# this crate won't be published, we always use the local version
opendal = { version = ">=0", path = "../../core", features = [
+ "blocking",
# These are default features before v0.46. TODO: change to optional features
"services-azblob",
"services-azdls",
@@ -50,3 +51,4 @@ opendal = { version = ">=0", path = "../../core", features = [
"services-webhdfs",
"services-azfile",
] }
+tokio = { version = "1", features = ["full"] }
diff --git a/bindings/php/src/lib.rs b/bindings/php/src/lib.rs
index 5999e0000..8243f644e 100644
--- a/bindings/php/src/lib.rs
+++ b/bindings/php/src/lib.rs
@@ -17,6 +17,7 @@
use std::collections::HashMap;
use std::str::FromStr;
+use std::sync::LazyLock;
use ::opendal as od;
use ext_php_rs::binary::Binary;
@@ -26,8 +27,15 @@ use ext_php_rs::flags::DataType;
use ext_php_rs::prelude::*;
use ext_php_rs::types::Zval;
+static RUNTIME: LazyLock<tokio::runtime::Runtime> = LazyLock::new(|| {
+ tokio::runtime::Builder::new_multi_thread()
+ .enable_all()
+ .build()
+ .unwrap()
+});
+
#[php_class(name = "OpenDAL\\Operator")]
-pub struct Operator(od::BlockingOperator);
+pub struct Operator(od::blocking::Operator);
#[php_impl(rename_methods = "none")]
impl Operator {
@@ -35,7 +43,11 @@ impl Operator {
let scheme = od::Scheme::from_str(&scheme_str).map_err(format_php_err)?;
let op = od::Operator::via_iter(scheme, config).map_err(format_php_err)?;
- Ok(Operator(op.blocking()))
+ let handle = RUNTIME.handle();
+ let _enter = handle.enter();
+ let op = od::blocking::Operator::new(op).map_err(format_php_err)?;
+
+ Ok(Operator(op))
}
/// Write string into given path.