9951 explained code solutions for 126 technologies

php-swooleCLI server example

use Swoole\Http\Server;

$srv = new Swoole\HTTP\Server('', 81);

$srv->on('Start', function($srv) { echo 'started'; });
$srv->on('Request', function($req, $res) { $res->end('Hi'); });

$srv->start();ctrl + c

variable will contain server object


HTTP server class

listen on localhost interface


listen on 81 port


listen to server start event

echo 'started'

output this to cli when server starts


listen to requests from client


send Hi text to the client and end request