Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/utopia-php/websocket
Lite & fast micro PHP WebSocket server abstraction that is **easy to use**.
https://github.com/utopia-php/websocket
hacktoberfest
Last synced: 26 days ago
JSON representation
Lite & fast micro PHP WebSocket server abstraction that is **easy to use**.
- Host: GitHub
- URL: https://github.com/utopia-php/websocket
- Owner: utopia-php
- License: mit
- Created: 2021-06-21T09:42:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T06:29:46.000Z (7 months ago)
- Last Synced: 2024-11-08T11:13:37.017Z (about 1 month ago)
- Topics: hacktoberfest
- Language: PHP
- Homepage:
- Size: 146 KB
- Stars: 12
- Watchers: 7
- Forks: 13
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-swoole - Utopia WebSocket - A simple and lite abstraction layer around a WebSocket server. This library is aiming to be as simple and easy to learn and use. (HTTP and WebSocket)
README
# Utopia WebSocket
[![Build Status](https://travis-ci.com/utopia-php/system.svg?branch=main)](https://travis-ci.com/utopia-php/websocket)
![Total Downloads](https://img.shields.io/packagist/dt/utopia-php/websocket.svg)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord)](https://appwrite.io/discord)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](https://appwrite.io).
Although this library is part of the [Utopia Framework](https://github.com/utopia-php/framework) project it is dependency free and can be used as standalone with any other PHP project or framework.
## Getting Started
Install using composer:
```bash
composer require utopia-php/websocket
```Init in your application:
```php
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](http://www.opensource.org/licenses/mit-license.php)