1. Go to this page and download the library: Download obray/socket-server 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/ */
obray / socket-server example snippets
er = new \obray\SocketServer('tcp', '127.0.0.1', 8080);
$server->registerHandler(new \obray\handlers\EchoServer());
$server->start();
$server->start(new \obray\handlers\EchoServer());
class Handler extends \obray\base\SocketServerBaseHandler
{
public function onData(string $data, int $readLength, \obray\interfaces\SocketConnectionInterface $connection)
{
$connection->qWrite($data);
return false;
}
}
$handler = new \obray\base\SocketServerBaseHandler(function ($message) {
error_log($message);
});
public function onStart(\obray\SocketServer $server): void
{
$server->watchTimer(5, 30, function () {
// Recurring application work.
});
}