GosWebSocketBundle is a Symfony bundle built on top of Ratchet and Autobahn|JS designed to bring together websocket functionality in an easy-to-use application architecture.
Much like Socket.IO, it provides both a websocket server and client implementation ensuring you have to write as little as possible to get your application up and running.
The bundle includes:
- PHP Websocket server (IO / WAMP) built on Ratchet
- JavaScript Websocket client (IO / WAMP) built on Autobahn|JS
- PubSub Router integration
- RPC support
- Integration with Symfony's Security component to share user authentication with the web frontend
- Repeating periodic function calls
To install this bundle, run the following Composer command:
composer require gos/web-socket-bundle
For an application using Symfony Flex the bundle should be automatically registered, but if not you will need to add it to your config/bundles.php
file.
<?php
return [
// ...
Gos\Bundle\PubSubRouterBundle\GosPubSubRouterBundle::class => ['all' => true],
Gos\Bundle\WebSocketBundle\GosWebSocketBundle::class => ['all' => true],
];
The following is the minimum configuration necessary to use the bundle.
# config/packages/gos_web_socket.yaml
gos_web_socket:
server:
# The host IP address on the server which connections for the websocket server are accepted.
host: 127.0.0.1
# The port on the server which connections for the websocket server are accepted.
port: 8080
router:
resources:
-
resource: '%kernel.project_dir%/config/pubsub/websocket/*'
type: 'glob'
With the bundle installed and configured, you can now launch the websocket server through your Symfony application's command-line console.
php bin/console gos:websocket:server
If everything is successful, you will see something similar to the following:
INFO [websocket] Starting web socket
INFO [websocket] Launching Ratchet on 127.0.0.1:8080 PID: 12345
Congratulations, your websocket server is now running. However, you will still need to add integrations to your application to fully use the bundle.