• Stars
    star
    310
  • Rank 134,926 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 1 year ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use any async Rust library from PHP!

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!):

More Repositories

1

MadelineProto

Async PHP client API for the telegram MTProto protocol
PHP
2,806
star
2

tg-file-decoder

Decode Telegram bot API file IDs
PHP
58
star
3

MadelineProtoDocs

Async PHP client/server API for the telegram MTProto protocol
46
star
4

magnaluna

Telegram webradio based on MadelineProto
PHP
29
star
5

madelineTon.js

Pure JS client-side implementation of the Telegram TON blockchain protocol
JavaScript
24
star
6

php-libtgvoip

PHP extension that wraps the telegram VoIP library.
C++
23
star
7

PrimeModule

PHP Prime module capable of doing prime factorization of huge numbers very quickly.
PHP
14
star
8

AsyncOrm

Async ORM based on AMPHP v3 and fibers.
PHP
12
star
9

PHPStruct

PHP implementation of Python's struct module.
PHP
11
star
10

schemas

Repo for MadelineProto TL schemas
10
star
11

captionbot-clients

Captionbot.ai API clients in various languages.
Shell
10
star
12

deeptelegram

Repository for the Deep Telegram app
C
9
star
13

MagicalSerializer

Serialize internal PHP objects!
PHP
9
star
14

downloadRenameBot

2gb+ Telegram file/YouTube upload&renamer bot based on MadelineProto
PHP
9
star
15

dns-over-https

Async DNS-over-HTTPS resolution for AMPHP.
PHP
7
star
16

better-prometheus

A better Prometheus library for PHP applications.
PHP
7
star
17

rpc-db

Database of Telegram MTProto RPC errors and their descriptions
Ruby
7
star
18

class-finder

Fork of haydenpierce/class-finder with support for traits and interfaces
PHP
7
star
19

telegram-entities

A library to work with Telegram UTF-16 styled text entities.
PHP
6
star
20

learn-bash

Script to learn bash scripting
Shell
5
star
21

pif-tdpony

PHP interface for tdlib
C++
5
star
22

loop

Loop abstraction for AMPHP
PHP
4
star
23

pipesbot

Telegram bot capable of creating pipelines between other bots, based on MadelineProto
HTML
4
star
24

ipc

Async IPC component for AMPHP
PHP
4
star
25

telerpc

API for reporting Telegram MTProto RPC errors
PHP
4
star
26

stun

A pure PHP async STUN implementation.
PHP
4
star
27

mklwp

Live wallpaper creator for Android
Smali
4
star
28

danog.github.io

My website
HTML
3
star
29

web2fb

bash script to download videos from youtube/dailymotion/etc and upload them on a facebook page
Shell
3
star
30

bna

bash script that explains the central dogma (DNA) using the bash scripting language
Shell
3
star
31

id3bot

Repo of the id3bot
Shell
3
star
32

scapy-tools

Tiny set of network tools written in python using scapy, + a custom wip implementation of scapy
Python
3
star
33

tgseclib

PHP Secure Communications Library (+Telegram-specific AES IGE primitives) - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc
PHP
3
star
34

gigaclone

Script to clone the profile.gigaset.net firmware website
HTML
3
star
35

PrimeModule-ext

C++ header-only library, binary and FFI library for factorizing huge 64-bit numbers.
C++
3
star
36

phpdoc

Simple markdown PHPDOC documentation generator with psalm type annotation support.
PHP
2
star
37

php-login-freelancer

Bootstrap php login website
CSS
2
star
38

toncontest

My submission to the TON blockchain contest
Shell
2
star
39

LibDNSJson

Encoder/decoder for google's JSON DNS message format based on libdns
PHP
2
star
40

SMSActivate

OOP wrapper for sms-activate.ru
PHP
2
star
41

jit_bugs

A repo full of reproducers for PHP JIT bugs.
Shell
2
star
42

LibDNSNative

Encoder/decoder for PHP's dns_get_record raw format based on libdns
PHP
2
star
43

audiokeychain-clients

Repository containing clients for the audiokeychain.com website
Shell
2
star
44

fantasiadanza.github.io

Fantasia Danza Rovigo :)
HTML
2
star
45

tonProxy

Websocket proxy for the TON blockchain ADNL protocol
PHP
2
star
46

tg-dialog-id

A library to work with Telegram bot API dialog IDs.
PHP
2
star
47

yayponies-ipfs

Deploy a yayponies mirror on IPFS
Shell
1
star
48

git-reset-repo

Bash script that resets all commits of a git repo
Shell
1
star
49

yawarehouse

Yet another warehouse implementation
Ruby
1
star
50

simple-slideshare-downloader

Simple slideshare downloader script
Shell
1
star
51

informatica

Repo for ICT exercises
C#
1
star
52

AltervistaUserBot

Source aggiornato della guida t.me/altervistauserbot
PHP
1
star
53

tgcalls_cli

CMake
1
star
54

filtersbot

repository of the filters bot
PHP
1
star
55

danuntu

Mirror of the website of an old project of mine, danuntu
HTML
1
star