{"id":20930129,"url":"https://github.com/uzdevid/yii2-websocket","last_synced_at":"2026-03-17T01:49:20.224Z","repository":{"id":206971585,"uuid":"718128438","full_name":"uzdevid/yii2-websocket","owner":"uzdevid","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-17T08:52:04.000Z","size":78,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-02T06:35:43.430Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/uzdevid.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-13T12:49:17.000Z","updated_at":"2024-07-17T08:51:55.000Z","dependencies_parsed_at":"2024-07-17T10:46:55.083Z","dependency_job_id":"b201d3d5-5c07-45e4-a120-dd7cf678e083","html_url":"https://github.com/uzdevid/yii2-websocket","commit_stats":null,"previous_names":["uzdevid/yii2-websocket"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzdevid%2Fyii2-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzdevid%2Fyii2-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzdevid%2Fyii2-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uzdevid%2Fyii2-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uzdevid","download_url":"https://codeload.github.com/uzdevid/yii2-websocket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254003435,"owners_count":21997887,"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":[],"created_at":"2024-11-18T21:29:16.414Z","updated_at":"2026-03-17T01:49:15.201Z","avatar_url":"https://github.com/uzdevid.png","language":"PHP","readme":"# WebSocket Application for Yii2 framework\n\nYii2 WebSocket Application is a powerful and flexible extension for the Yii2 framework that enables developers to integrate a WebSocket server into their applications. Built on top of the `workerman/workerman` package, this extension is ideal for creating real-time features such as chats, notifications, online games, and other interactive applications that require a persistent connection to the server.\n\n### Installation\n\n```bash\ncomposer require uzdevid/yii2-websocket\n```\n\n### Usage\n\nApplication configuration similar to the default application.\n\nCreate config file `\u003cproject_root\u003e/socket/config/main.php` \n\n```php\nuse UzDevid\\WebSocket\\Server\\WebSocketServer;\n\n$params = array_merge(\n    require __DIR__ . '/../../common/config/params.php',\n    require __DIR__ . '/params.php',\n);\n\nreturn [\n    'id' =\u003e 'web-socket-app',\n    'basePath' =\u003e dirname(__DIR__),\n    'controllerNamespace' =\u003e 'socket\\\\controllers',\n    'webSocketServer' =\u003e [\n        'class' =\u003e WebSocketServer::class,\n        'host' =\u003e '0.0.0.0',\n        'port' =\u003e 8080,\n        'count' =\u003e 1\n    ],\n    'components' =\u003e [],\n    'params' =\u003e $params,\n];\n```\n\nWith the current settings, the web socket server will listen on `0.0.0.0:8080`. Count of workers: 1\n\n---\nMessage processing occurs through the controller and action. Create `\u003cproject-root\u003e/socket/EchoController` controller.\n\n```php\nnamespace socket\\controllers;\n\nuse UzDevid\\WebSocket\\Controller;\nuse UzDevid\\WebSocket\\Server\\Dto\\Client;\n\nclass EchoController extends Controller {\n    /**\n     * @param Client $client\n     * @param array $payload\n     * @return void\n     */\n    public function actionEcho(Client $client, array $payload): void {\n        $client-\u003euser-\u003esend('echo:echo', ['currentTime' =\u003e time()]);\n    }\n}\n```\n\n---\n\nCreate entry point file named `\u003cproject_root\u003e/run`\n\n```php\n#!/usr/bin/env php\n/**\n * Yii WebSocket bootstrap file.\n */\nuse UzDevid\\WebSocket\\Application;\n\nrequire __DIR__ . '/vendor/autoload.php';\nrequire __DIR__ . '/vendor/yiisoft/yii2/Yii.php';\nrequire __DIR__ . '/common/сonfig/bootstrap.php';\nrequire __DIR__ . '/socket/сonfig/bootstrap.php';\n\n$config = yii\\helpers\\ArrayHelper::merge(\n    require __DIR__ . '/common/сonfig/main.php',\n    require __DIR__ . '/socket/сonfig/main.php',\n);\n\n$application = new Application($config);\n$application-\u003erun();\n```\n\n---\n\nTo start the server you need to run the command:\n\n```bash\nphp \u003cproject_root\u003e/run start\n```\n\nFor testing, we can use the Postman program. You need to create a web socket connection. You need to create a web socket connection with port `ws://0.0.0.0:8080`, which is specified in the application configuration.\n\nMessage Body Format. \n```json\n{\n  \"method\": \"echo:echo\",\n  \"payload\": {}\n}\n```\nThe `method` parameter is similar to a regular url, the only difference is in the separator `:` What is specified in the payload parameter You can get them in the action arguments.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzdevid%2Fyii2-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuzdevid%2Fyii2-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuzdevid%2Fyii2-websocket/lists"}