revolt/event-loop-adapter-react

Makes any ReactPHP based library run on top of the Revolt event loop.

v1.1.1 2023-10-15 19:25 UTC

This package is auto-updated.

Last update: 2024-10-15 21:27:03 UTC


README

Stable License

revolt/event-loop-adapter-react makes any ReactPHP library run on top of the Revolt event loop.

Installation

composer require revolt/event-loop-adapter-react

Usage

Everywhere where a ReactPHP library requires an instance of LoopInterface, you just pass Loop::get() as normal. We automatically set up everything to run the ReactPHP library on the Revolt event loop.

<?php

require 'vendor/autoload.php';

use React\EventLoop\Loop;
use Revolt\EventLoop;

$app = function ($request, $response) {
    $response->writeHead(200, array('Content-Type' => 'text/plain'));
    $response->end("Hello World\n");
};

$socket = new React\Socket\Server(Loop::get());
$http = new React\Http\Server($socket, Loop::get());

$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";

$socket->listen(1337);

EventLoop::run();