diff --git a/README.md b/README.md index 5fdb0ca..73c31c5 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,58 @@ This library allows you to use any async rust library from PHP, asynchronously. It's fully integrated with [revolt](https://revolt.run): this allows full compatibility with [amphp](https://amphp.org), [PSL](https://github.com/azjezz/psl) and reactphp. -## Usage +## Example + +Here's an example, using the async Rust [reqwest](https://docs.rs/reqwest/latest/reqwest/) library to make asynchronous HTTP requests from PHP: + +```php + \reqwest_async_wakeup()); + self::$id = EventLoop::onReadable($f, fn () => \Client::wakeup()); } public static function reference(): void{ @@ -23,6 +25,6 @@ public static function unreference(): void { } public static function __callStatic(string $name, array $args): mixed { - return \Client::$name($args); + return \Client::$name(...$args); } } diff --git a/examples/reqwest/src/lib.rs b/examples/reqwest/src/lib.rs index 1d2357b..cda6a0c 100644 --- a/examples/reqwest/src/lib.rs +++ b/examples/reqwest/src/lib.rs @@ -13,11 +13,12 @@ impl Client { pub fn wakeup() -> PhpResult<()> { EventLoop::wakeup() } - pub async fn get(url: &str) -> String { - reqwest::get("https://www.rust-lang.org") + pub async fn get(url: &str) -> anyhow::Result { + Ok(reqwest::get(url) .await? .text() .await? + ) } } diff --git a/examples/reqwest/test.php b/examples/reqwest/test.php index 109c70f..12e9cb1 100644 --- a/examples/reqwest/test.php +++ b/examples/reqwest/test.php @@ -1,5 +1,25 @@