Download the PHP package cydrickn/swoole-websocket-bundle without Composer
On this page you can find all versions of the php package cydrickn/swoole-websocket-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cydrickn/swoole-websocket-bundle
More information about cydrickn/swoole-websocket-bundle
Files in cydrickn/swoole-websocket-bundle
Package swoole-websocket-bundle
Short Description Swoole Websocket for Symfony
License MIT
Informations about the package swoole-websocket-bundle
Swoole Websocket Bundle
A bundle for websocket using swoole
Requirements
- Swoole or OpenSwoole
- PHP >= 8.1
- Symfony >= 6.1
Intallation
Add the package
Run the server
Commands
websocket:server
Run the websocket server
Options | Details | Default |
---|---|---|
host | The host of the server | 127.0.0.1 |
port | The port of the server | 8000 |
Events
This bundle will have an event where you can listen
\Cydrickn\SwooleWebsocketBundle\Event\OpenEvent
This event will be trigger once a client have been connected to the server.
\Cydrickn\SwooleWebsocketBundle\Event\MessageEvent
This event will be trigger once the client send a message
\Cydrickn\SwooleWebsocketBundle\Event\CloseEvent
This event will be trigger once a client have been disconnected
Client connection using Javascript
For the basic way on connecting to websocket you can use the Browser Websocket
Use it in runtime
Using the command is fine, but if you happen you want to serve this using symfony runtime you can do so.
-
First you need to include symfony/runtime
- Next run your
public/index.php
with env APP_RUNTIME
Runtime Configuration
For runtime configuration you can add it to your public/index.php
Key | Details | Default |
---|---|---|
host | The host of the server | 127.0.0.1 |
port | The port of the server | 8000 |
mode | The mode for server | 2 / SWOOLE_PROCESS |
sock_type | The socket type for server | 1 / SWOOLE_SOCK_TCP |
settings | The setting is base on swoole configuration | [] / Empty Array |
serve_http | Include to serve HTTP | false |
Example:
Also instead of having to server for websocket and http, you can just enable the
Serve HTTP
, by setting theserve_http
to true
Hot reloading
We already include a hor reloading for this bundle. To enable it you need to first require cydrickn/php-watcher
Hot reloading is only available if you are using runtime
Now add to your APP_RUNTIME_OPTIONS
the hotReload
The basePath
should be your project folder
Socket IO
In this bundle you can also enable using socket.io implementation, to enable it first you need to install cydrickn/socketio
This implementation is only available if you are using runtime
Now add to your APP_RUNTIME_OPTIONS
set the socketio
to true
Adding a route to socket io
For pure socket io you will do this
You will use the Attribute Route of this bundle Cydrickn\SwooleWebsocketBundle\Attribute\RouteAttribute
In any of your service