Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cydrickn/thruway-swoole-transport

OpenSwoole / Swoole Websocket Transport for Thruway Router
https://github.com/cydrickn/thruway-swoole-transport

openswoole swoole thruway transport wamp-protocol wamp-router wamp-server websocket

Last synced: about 1 month ago
JSON representation

OpenSwoole / Swoole Websocket Transport for Thruway Router

Awesome Lists containing this project

README

        

# Swoole Thruway Transport

OpenSwoole / Swoole Websocket Transport for Thruway Router

## Prerequisite:
- PHP version >= 8.1
- [OpenSwoole](https://openswoole.com/docs/get-started/installation)
- [voryx/thruway](https://github.com/voryx/Thruway)

## Installation

```sh
composer require cydrickn/thruway-swoole-transport
```

## Example

### Ouside the worker start

```php
addTransportProvider($transportProvider);

$server->addListener(WebsocketServer::EVENT_SERVER_START, function () use($transportProvider, $server) {
\Thruway\Logging\Logger::info($transportProvider, 'Websocket listening on 0.0.0.0:9000');
$server->shutdown();
});

$router->start(false);
```

### Inside Worker Start

```php
addListener(WebsocketServer::EVENT_SERVER_START, function () {
\Thruway\Logging\Logger::info(null, 'Websocket listening on 0.0.0.0:9000');
});

$server->addListener(WebsocketServer::EVENT_WORKER_START, function () use($server) {
$transportProvider = new SwooleTransportProvider($server);

$router = new Router(new SwooleLoop());
$router->addTransportProvider($transportProvider);

$router->start(false);
});
```