- ReactPHP
require 'vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); $socket = new React\Socket\Server('127.0.0.1:8080', $loop); $socket->on('connection', function ($conn) { $conn->on('data', function ($data) use ($conn) { $conn->write(strtoupper($data)); }); }); $loop->run();
- Swoole
$server = new Swoole\Server("127.0.0.1", 9501); $server->on('receive', function ($server, $fd, $from_id, $data) { $server->send($fd, strtoupper($data)); }); $server->start();
- Amp
require 'vendor/autoload.php'; use Amp\Socket\Server; use Amp\Socket\Client; Amp\Loop::run(function () { $server = new Server("127.0.0.1:8080"); $server->on('connection', function (Client $client) { $client->on('data', function ($data) use ($client) { $client->write(strtoupper($data)); }); }); });