utopia-php / websocket
A simple abstraction for WebSocket servers.
Installs: 67 182
Dependents: 1
Suggesters: 0
Security: 0
Stars: 13
Watchers: 7
Forks: 13
Open Issues: 0
Requires
- php: >=8.0
Requires (Dev)
- laravel/pint: ^1.15
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.5.5
- swoole/ide-helper: 5.1.2
- textalk/websocket: 1.5.2
- workerman/workerman: ^4.0
This package is auto-updated.
Last update: 2024-12-21 07:36:02 UTC
README
Utopia WebSocket is a simple and lite abstraction layer around a WebSocket server. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.
Although this library is part of the Utopia Framework project it is dependency free and can be used as standalone with any other PHP project or framework.
Getting Started
Install using composer:
composer require utopia-php/websocket
Init in your application:
<?php require_once __DIR__ . '/../../vendor/autoload.php'; use Utopia\WebSocket; $adapter = new WebSocket\Adapter\Swoole(); $adapter->setPackageMaxLength(64000); $server = new WebSocket\Server($adapter); $server->onStart(function () { echo "Server started!"; }); $server->onWorkerStart(function (int $workerId) { echo "Worker {$workerId} started!"; }); $server->onOpen(function (int $connection, $request) { echo "Connection {$connection} established!"; }); $server->onMessage(function (int $connection, string $message) { echo "Message from {$connection}: {$message}"; }); $server->onClose(function (int $connection) { echo "Connection {$workerId} closed!"; }); $server->start();
System Requirements
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
Copyright and license
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php