Download the PHP package snoke/symfony-websocket without Composer
On this page you can find all versions of the php package snoke/symfony-websocket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package symfony-websocket
Symfony Websocket Server Bundle
RFC 6455-compliant Websocket Server Bundle for Symfony 7
installation
checkout library
composer req snoke/symfony-websocket
modify config/packages/snoke_websocket.yaml
:
`
if you do not want to use TLS: ` note that websockets without TLS only work on localhost (tho you can still use Stunnel to wrap them into a TLS Connection)
getting started
Starting the WebSocket Server
Use the Symfony console command to start the WebSocket server
php bin/console websocket:start
You can optionally specify the IP address and port:
php bin/console websocket:start --ip=127.0.0.1 --port=9000
testing the server
you can connect and send a message to your websocket server with following command:
php bin/console websocket:test
Registering Event Listeners
to react to WebSocket events, create your own listeners.
test again with php bin/console websocket:test
Mapping Users
the ConnectionWrapper contains getter and setter to match a connection with a Symfony UserInterface
Broadcasting
you can access all connections in the Listeners through the event
Available Events
- ServerStarted: Triggered when the WebSocket server is started.
- ConnectionOpened: Triggered when a new WebSocket connection is established.
- ConnectionClosed: Triggered when a WebSocket connection is closed.
- Error: Triggered when an error occurs.
- MessageReceived: Triggered when a WebSocket message is received.
- TextFrame: Triggered after MessageReceived when a text message frame is received (WebSocketOpcode::TextFrame).
- BinaryFrame: Triggered after MessageReceived when a binary message frame is received (WebSocketOpcode::BinaryFrame).
- ContinuationFrame: Triggered after MessageReceived d when a continuation frame is received for a fragmented message (WebSocketOpcode::ContinuationFrame).
- ConnectionCloseFrame: Triggered after MessageReceived when a connection close frame is received (WebSocketOpcode::ConnectionCloseFrame).
- PingFrame: Triggered after DataReceived when a ping frame is received (WebSocketOpcode::PingFrame).
- PongFrame: Triggered after DataReceived when a pong frame is received (WebSocketOpcode::PongFrame).
Advanced
Message Fragmentation
The server handles fragmented messages using the following opcodes:
TextFrame (0x1)
BinaryFrame (0x2)
ContinuationFrame (0x0)
When a message is fragmented:
The first frame (Text or Binary Frame) starts with FIN set to 0.
Subsequent frames (Continuation Frames) continue the message with FIN set to 0 until the last frame.
The last frame of the message has FIN set to 1, indicating the end of the fragmented message.
Ensure your application handles fragmented messages correctly based on RFC 6455 specifications.
All versions of symfony-websocket with dependencies
react/socket Version ^1.15
react/event-loop Version ^1.5
symfony/console Version ^7.1
symfony/event-dispatcher Version ^7.1
doctrine/collections Version ^2.2
psr/log Version ^3.0
symfony/dependency-injection Version ^7.1