PHP Socket框架的示例代码有哪些

avatar
作者
猴君
阅读量:0

  1. 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(); 
  1. 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(); 
  1. 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));         });     }); }); 

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!