{"id":15077151,"url":"https://github.com/bordeux/websocket-bundle","last_synced_at":"2025-10-05T11:31:39.015Z","repository":{"id":62496094,"uuid":"52657534","full_name":"bordeux/websocket-bundle","owner":"bordeux","description":"Symfony 3 Websocket bundle","archived":true,"fork":false,"pushed_at":"2017-05-30T23:33:22.000Z","size":13,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-19T07:42:20.617Z","etag":null,"topics":["symfony","symfony-bundle","symfony3","websocket","websocket-bundle","websocket-php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bordeux.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-27T08:30:15.000Z","updated_at":"2023-01-28T01:18:50.000Z","dependencies_parsed_at":"2022-11-02T11:32:20.437Z","dependency_job_id":null,"html_url":"https://github.com/bordeux/websocket-bundle","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bordeux%2Fwebsocket-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bordeux%2Fwebsocket-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bordeux%2Fwebsocket-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bordeux%2Fwebsocket-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bordeux","download_url":"https://codeload.github.com/bordeux/websocket-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235393591,"owners_count":18982818,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["symfony","symfony-bundle","symfony3","websocket","websocket-bundle","websocket-php"],"created_at":"2024-09-25T04:03:40.487Z","updated_at":"2025-10-05T11:31:33.732Z","avatar_url":"https://github.com/bordeux.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony Websocket Bundle\nSimple and great websocket manager.\n\n\n## Installation\n\n```\ncomposer require bordeux/websocket-bundle\n```\n\n## Run\n\n```\nphp app/console bordeux:websocket:bundle\n```\n\n## Edit Appkernel\n\n```php\n    public function registerBundles()\n    {\n        $bundles = array(\n\t\t\t...\n            new Bordeux\\WebsocketBundle\\BordeuxWebsocketBundle(),\n\t\t\t....\n        );\n\n        return $bundles;\n    }\n\n```\n\n## Create Websocket Controller\n```php\n\u003c?php\n\n/**\n * File must be on \u003cyour-boundle\u003e/Websocket/\u003cyour-name\u003eWebsocket.php\n */\n\nnamespace Tattool\\Bundle\\MessagesBundle\\Websocket;\n\nuse Bordeux\\WebsocketBundle\\Websocket\\Client;\nuse Bordeux\\WebsocketBundle\\Websocket\\Message;\nuse Bordeux\\WebsocketBundle\\Websocket\\Websocket;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\Routing\\Route;\nuse Symfony\\Component\\Routing\\RouteCollection;\n\n/**\n * Class SimpleWebsocket\n * @author Krzysztof Bednarczyk\n * @package Tattool\\Bundle\\MessagesBundle\\Websocket\n */\nclass SimpleWebsocket extends Websocket\n{\n\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @param RouteCollection $collection\n     */\n    public function configureRoutes(RouteCollection $collection)\n    {\n        $collection-\u003eadd(\"user.messages\", new Route(\n            \"/ws/user/messages/{id}/{accessToken}/\", [\n            //defaults\n        ], [\n                \"id\" =\u003e \"\\d+\", //requirements\n                \"accessToken\" =\u003e \"[a-zA-Z0-9_\\-]+\",\n            ]\n        ));\n    }\n\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @param Client $client\n     * @return void\n     */\n    public function onConnect(Client $client)\n    {\n\n        /**\n         * Example url:\n         * wss://localhost.org/ws/user/messages/5/a8f5f167f44f4964e6c998dee827110c/?lorem=95\n         */\n        /** @var Request $request */\n        $request = $client-\u003egetRequest();\n        $request-\u003egetUri(); //uri\n        $request-\u003egetHost(); //host\n        $request-\u003egetClientIp(); //client ip\n\n\n        $request-\u003ecookies-\u003eget(\"\u003cyour-cookies\u003e\");\n\n        $request-\u003eattributes-\u003eget(\"id\"); //result: 5\n        $request-\u003eattributes-\u003eget(\"accessToken\"); //result: a8f5f167f44f4964e6c998dee827110c\n\n\n        $request-\u003equery-\u003eget(\"lorem\"); //result: 95\n\n        $client-\u003egetId(); //client id\n\n    }\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @param Client $client\n     * @return void\n     */\n    public function onError(Client $client)\n    {\n        $client-\u003ekill(); //kill client ;)\n    }\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @param Client $client\n     * @param Message $message\n     * @return void\n     */\n    public function onMessage(Client $client, Message $message)\n    {\n\n        $client-\u003esendMessage(new Message(\n            \"Hello World!\"\n        ));\n    }\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @param Client $client\n     * @return void\n     */\n    public function onDisconnect(Client $client)\n    {\n    }\n\n    /**\n     * @author Krzysztof Bednarczyk\n     * @return mixed\n     */\n    public function run()\n    {\n        //executed after initialize controller\n\n        $this-\u003egetLoop(); //loop factor for async\n\n        $this-\u003egetContainer(); //container\n\n        $this-\u003egetParameter(\"doctrine.class\"); //symfony parameters\n\n        $this-\u003egetDoctrine(); //doctrine\n    }\n\n}\n```\n\n\n## Configuration init.d\n\n1. Edit  [sf-websocket.sh](https://github.com/bordeux/websocket-bundle/blob/master/Resources/init.d/sf-websocket.sh) from Resources/init.d\n2. Execute as root:\n```bash\ncp \u003cyour-path\u003e/init.d/sf-websocket.sh /etc/init.d/sf-websocket\nchmod a+x /etc/init.d/sf-websocket\nupdate-rc.d sf-websocket defaults\n```\n\n\n## Configuration nginx proxy\n\n```nginx\nupstream websocketServers {\n    server 127.0.0.1:1337;\n    server 127.0.0.2:1337;\n    server 127.0.0.3:1337;\n    server 127.0.0.4:1337;\n}\n\nserver {\n    listen 443 ssl http2;\n    listen [::]:443 ssl http2;\n\n    ssl on;\n    ssl_certificate /www/cert/fullchain.pem;\n    ssl_certificate_key /www/cert/privkey.pem;\n    ssl_prefer_server_ciphers on;\n    ssl_ciphers 'kEECDH+ECDSA+AES128 kEECDH+ECDSA+AES256 kEECDH+AES128 kEECDH+AES256 kEDH+AES128 kEDH+AES256 DES-CBC3-SHA +SHA !aNULL !eNULL !LOW !kECDH !DSS !MD5 !EXP !PSK !SRP !CAMELLIA !SEED';\n\n    server_name ws.localhost.org;\n\tcharset utf-8;\n\tclient_max_body_size 1M;\n\n\taccess_log  off;\n\terror_log  /var/log/sf-websocket/error.log;\n\n    location / {\n        proxy_pass http://websocketServers;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n\t}\n\t\n}\n\n```\n\n\n\n## Connect\n\n```javascript\nvar connection = new WebSocket('wss://localhost.org/ws/user/messages/5/a8f5f167f44f4964e6c998dee827110c/?lorem=95');\n\n// When the connection is open, send some data to the server\nconnection.onopen = function () {\n\tconsole.log(\"opened!\");\n  connection.send('Ping'); // Send the message 'Ping' to the server\n};\n\n// Log errors\nconnection.onerror = function (error) {\n  console.log('WebSocket Error ' + error);\n};\n\n// Log messages from the server\nconnection.onmessage = function (e) {\n  console.log('Server: ' + e.data);\n};\n```\n\n\n## !?!?!??!?! PROFIT !?!?!??!?!?\n\n\n\nSponsors:\n[Kursy pierwszej pomocy - Katowice](https://www.p-med.pl/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbordeux%2Fwebsocket-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbordeux%2Fwebsocket-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbordeux%2Fwebsocket-bundle/lists"}