revolt/event-loop-adapter-react

使任何基于ReactPHP的库在Revolt事件循环上运行。

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

This package is auto-updated.

Last update: 2024-09-15 21:19:42 UTC


README

Stable License

revolt/event-loop-adapter-react 使任何 ReactPHP 库在 Revolt事件循环 上运行。

安装

composer require revolt/event-loop-adapter-react

使用

在任何需要LoopInterface实例的ReactPHP库中,您只需按正常方式传递Loop::get()即可。我们会自动设置一切,以便在 Revolt事件循环 上运行ReactPHP库。

<?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();