{"id":14971304,"url":"https://github.com/yiiplus/yii2-websocket","last_synced_at":"2025-10-26T15:30:22.850Z","repository":{"id":57087174,"uuid":"161865559","full_name":"yiiplus/yii2-websocket","owner":"yiiplus","description":"使用yii2封装 websocket 扩展","archived":false,"fork":false,"pushed_at":"2019-01-30T08:54:41.000Z","size":108,"stargazers_count":21,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-31T20:55:50.618Z","etag":null,"topics":["swoole","websocket","workerman","yii2-extension"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/yiiplus/yii2-websocket","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiiplus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-15T03:22:09.000Z","updated_at":"2023-05-22T02:14:19.000Z","dependencies_parsed_at":"2022-08-24T22:50:26.870Z","dependency_job_id":null,"html_url":"https://github.com/yiiplus/yii2-websocket","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiiplus%2Fyii2-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiiplus%2Fyii2-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiiplus%2Fyii2-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiiplus%2Fyii2-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiiplus","download_url":"https://codeload.github.com/yiiplus/yii2-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238347894,"owners_count":19457012,"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":["swoole","websocket","workerman","yii2-extension"],"created_at":"2024-09-24T13:44:59.863Z","updated_at":"2025-10-26T15:30:22.327Z","avatar_url":"https://github.com/yiiplus.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-websocket\n\n在 yii2 下运行 WebSocket 服务。\n\n[![Latest Stable Version](https://poser.pugx.org/yiiplus/yii2-websocket/v/stable)](https://packagist.org/packages/yiiplus/yii2-websocket)\n[![Total Downloads](https://poser.pugx.org/yiiplus/yii2-websocket/downloads)](https://packagist.org/packages/yiiplus/yii2-websocket)\n[![License](https://poser.pugx.org/yiiplus/yii2-websocket/license)](https://packagist.org/packages/yiiplus/yii2-websocket)\n\n## 驱动支持\n- [swoole](docs/guide/dirver-swoole.md)\n- ~~[workerman](docs/guide/dirver-workerman.md)~~\n\n## 安装\n\n安装此扩展程序的首选方法是通过 [composer](http://getcomposer.org/download/).\n\n编辑运行\n\n```bash\nphp composer.phar require --prefer-dist yiiplus/yii2-websocket \"^1.0.0\"\n```\n\n或添加配置到项目目录下的`composer.json`文件的 require 部分\n\n```\n\"yiiplus/yii2-websocket\": \"^1.0.0\"\n```\n\n## 基本使用\n\n每个 channel 的功能都需要定义一个单独的类。例如，如果你需要为指定客户端推送一条消息，则该类可能如下所示：\n\n```php\nnamespace xxx\\channels;\n\nclass PushMessageChannel extends BaseObject implements \\yiiplus\\websocket\\ChannelInterface\n{\n\tpublic function execute($fd, $data)\n\t{\n\t\treturn [\n\t\t\t$fd, // 第一个参数返回客户端ID，多个以数组形式返回\n\t\t\t$data // 第二个参数返回需要返回给客户端的消息\n\t\t];\n\t}\n\n\tpublic function close($fd)\n\t{\n\t\treturn;\n\t}\n}\n```\n\n以下是从客户端发送消息的方法：\n\n```php\nYii::$app-\u003ewebsocket-\u003esend(['channel' =\u003e 'push-message', 'message' =\u003e '用户 xxx 送了一台飞机！']);\n```\n\n执行任务的确切方式取决于使用的驱动程序。 大多数驱动程序可以使用控制台命令运行，组件需要在应用程序中注册。\n\n此命令启动一个守护进程，该守护进程维护一个 WebSocket Server，根据客户端发来的数据，处理相关 channel 的任务：\n\n```bash\nyii websocket/start\n```\n\n有关驱动程序特定控制台命令及其选项的更多详细信息，请参阅 [文档](docs/guide/)。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiiplus%2Fyii2-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiiplus%2Fyii2-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiiplus%2Fyii2-websocket/lists"}