1. Go to this page and download the library: Download naka1205/phpsocket library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
naka1205 / phpsocket example snippets
Naka507\Socket\Server;
$server = new Server();
//服务启动
$server->onWorkerStart = function($worker)
{
echo "New onWorkerStart\n";
};
//建立连接
$server->onConnect = function($connection)
{
echo "New Connection\n";
};
//接收请求
$server->onMessage = function($request, $response)
{
$response->write(' Hello World !!!');
$response->end();
};
$server->start();