revolt / event-loop-adapter-react
使任何基于ReactPHP的库在Revolt事件循环上运行。
v1.1.1
2023-10-15 19:25 UTC
Requires
- php: >=8.1
- react/async: ^4
- react/event-loop: ^1 || ^0.5
- revolt/event-loop: ^1 || ^0.2.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5.21
- psalm/phar: ^4.24
README
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();