Use any async Rust library from PHP!

Overview

php-tokio - Use any async Rust library from PHP!

Created by Daniil Gentili (@danog).

This library allows you to use any async rust library from PHP, asynchronously.

It's fully integrated with revolt: this allows full compatibility with amphp, PSL and reactphp.

Example

Here's an example, using the async Rust reqwest library to make asynchronous HTTP requests from PHP:

<?php

use Reqwest\Client;

use function Amp\async;
use function Amp\Future\await;

require 'vendor/autoload.php';

Client::init();

function test(int $delay): void {
    $url = "https://httpbin.org/delay/$delay";
    $t = time();
    echo "Making async reqwest to $url that will return after $delay seconds...".PHP_EOL;
    Client::get($url);
    $t = time() - $t;
    echo "Got response from $url after ~".$t." seconds!".PHP_EOL;
};

$futures = [];
$futures []= async(test(...), 5);
$futures []= async(test(...), 5);
$futures []= async(test(...), 5);

await($futures);

Usage:

cd examples/reqwest && \
    cargo build && \
    composer update && \
    php -d extension=../../target/debug/libexample_reqwest.so test.php

Result:

Making async reqwest to https://httpbin.org/delay/5 that will return after 5 seconds...
Making async reqwest to https://httpbin.org/delay/5 that will return after 5 seconds...
Making async reqwest to https://httpbin.org/delay/5 that will return after 5 seconds...
Got response from https://httpbin.org/delay/5 after ~5 seconds!
Got response from https://httpbin.org/delay/5 after ~5 seconds!
Got response from https://httpbin.org/delay/5 after ~5 seconds!

See the source code of the example for more info on how it works!

Built with php-tokio

Here's a list of async PHP extensions built with php-tokio (add yours by editing this file!):

You might also like...
Shiva library: Implementation in Rust of a parser and generator for documents of any type
Shiva library: Implementation in Rust of a parser and generator for documents of any type

Shiva Shiva library: Implementation in Rust of a parser and generator for documents of any type Features Common Document Model (CDM) for all document

A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

A simple Rust library for OpenAI API, free from complex async operations and redundant dependencies.

OpenAI API for Rust A community-maintained library provides a simple and convenient way to interact with the OpenAI API. No complex async and redundan

A Python package written in Rust for email verification without sending any emails.

PyRustify PyRustify is a Python package written in Rust that verifies the email addresses. Features Feature Description Syntax validation Checks if th

RBTC is cli to convert BTC to any currency and vice-versa.
RBTC is cli to convert BTC to any currency and vice-versa.

RBTC RBTC is cli to convert BTC to any currency and vice-versa. Building for source For build the binary just: $ cargo build To run as debug, just run

Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

Shellfirm - Intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification
Shellfirm - Intercept any risky patterns (default or defined by you) and prompt you a small challenge for double verification

shellfirm Opppppsss you did it again? ๐Ÿ˜ฑ ๐Ÿ˜ฑ ๐Ÿ˜ฐ Protect yourself from yourself! rm -rf * git reset --hard before saving? kubectl delete ns which going

โ˜„๐ŸŒŒ๏ธ  The minimal, blazing-fast, and infinitely customizable prompt for any shell
โ˜„๐ŸŒŒ๏ธ The minimal, blazing-fast, and infinitely customizable prompt for any shell

โ˜„๐ŸŒŒ๏ธ The minimal, blazing-fast, and infinitely customizable prompt for any shell

UniSBOM is a tool to build a software bill of materials on any platform with a unified data format.

UniSBOM is a tool to build a software bill of materials on any platform with a unified data format. Work in progress Support MacOS Uses system_profile

Releases(0.1.2)
Owner
Daniil Gentili
Go, C++, React, Node, PHP and Rust developer and Psalm maintainer. Netadm of AS198747. #StandWithUkraine ๐Ÿ‡บ๐Ÿ‡ฆ
Daniil Gentili
Standard Graphics is a command-line tool for printing 2D graphics from any language to any screen.

2D graphics in any programming language with just print statements!

Caleb Winston 123 Nov 20, 2022
A small subset of PHP implemented in Rust. ๐Ÿ˜

microphp A small subset of PHP implemented in Rust. About This project aims to implement a small subset of PHP's feature-set using a Rust powered pars

Ryan Chandler 5 Feb 7, 2022
Generate PHP code from Rust using a fluent API ๐Ÿ˜ ๐Ÿฆ€

PHP-Codegen Generate PHP code from Rust using a fluent API ?? ?? Rust PHP Usage To bring this crate into your repository, either add php_codegen to yo

PHP Rust Tools 7 Dec 24, 2022
Lapce plugin for the Php language.

lapce-php-intelephense Lapce plugin for the Php language. Prerequisites Install Intelephense, typically by running: $ npm i intelephense -g Settings S

null 3 Jan 9, 2023
A superset of PHP with extended syntax and runtime capabilities.

PXP PXP is a superset of the PHP programming language that provides an extended set of syntax rules and language features to improve developer experie

PXP 188 Jan 29, 2023
A opinionated and fast static analyzer for PHP.

TLDR; A static analyzer for PHP. It helps you catch common mistakes in your PHP code. These are the current checks implemented. Extending undefined cl

Denzyl Dick 11 Mar 6, 2023
PHP++ short for redditlang is a language created by the r/ProgrammerHumor subreddit discord members

RedditLang PHL ( ProgrammerHumor language ) or RedditLang is a language created by the r/ProgrammerHumor discord! The spec is avaliable here Why Reddi

elijah629 10 Jun 23, 2023
The fastest bloom filter in Rust. No accuracy compromises. Use any hasher.

b100m-filter The fastest bloom filter in Rust. No accuracy compromises. Use any hasher. Usage # Cargo.toml [dependencies] b100m-filter = "0.3.0" use b

null 4 Nov 19, 2023
That program use on platform windows. And if you write any text on uncorrect keyboard layout, that program for that.

?? This program is designed to translate text into the correct layout when typing is incorrect. ?? Example ghbdtn -> ะฟั€ะธะฒะตั‚ Just (by default) pressing

Gest Se 5 Jan 26, 2023
ISG lets you use YouTube as cloud storage for ANY files, not just video

I was working on this instead of my finals, hope you appreciate it. I'll add all relevant executables when I can Infinite-Storage-Glitch AKA ISG (writ

HistidineDwarf 3.6k Feb 23, 2023