{"id":37014274,"url":"https://github.com/ledccn/gateway-worker","last_synced_at":"2026-01-14T01:24:57.942Z","repository":{"id":312513554,"uuid":"1047757222","full_name":"ledccn/gateway-worker","owner":"ledccn","description":"Webman plugin ledc/gateway-worker","archived":false,"fork":false,"pushed_at":"2025-09-10T08:25:41.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-10T12:00:02.681Z","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/ledccn.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-31T06:43:13.000Z","updated_at":"2025-09-10T08:25:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1750030-f723-4f5a-9bfb-e09f3949ce6f","html_url":"https://github.com/ledccn/gateway-worker","commit_stats":null,"previous_names":["ledccn/gateway-worker"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/ledccn/gateway-worker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledccn%2Fgateway-worker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledccn%2Fgateway-worker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledccn%2Fgateway-worker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledccn%2Fgateway-worker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ledccn","download_url":"https://codeload.github.com/ledccn/gateway-worker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ledccn%2Fgateway-worker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-14T01:24:57.369Z","updated_at":"2026-01-14T01:24:57.926Z","avatar_url":"https://github.com/ledccn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webman基础插件之 GatewayWorker\n\n## 简介\n\n基于GatewayWorker的webman基础插件，通过命令行单独启动，重启 `webman` 时，不影响 `GatewayWorker` ，从而与业务解耦。\n\n## 特性\n\n- 命令行单独启动\n- 可单独配置 `Register`、`Gateway`、`BusinessWorker` 各进程是否启动\n- 内置通用的 `BusinessWorker` 事件处理类 `\\Ledc\\GatewayWorker\\EventHandler`\n- 内置事件枚举 `\\Ledc\\GatewayWorker\\EventEnums`\n\n## 安装\n\nPHP版本：\u003e=8.3\n\n```shell\ncomposer require ledc/gateway-worker\n```\n\n忽略扩展安装\n\n```shell\ncomposer require ledc/gateway-worker --ignore-platform-req=ext-posix -W\n```\n\n## 启动\n\n```shell\nphp webman gateway:worker start\n```\n\n## 停止\n\n```shell\nphp webman gateway:worker stop\n```\n\n## nginx配置\n\n```conf\nlocation /websocket\n{\n  proxy_pass http://127.0.0.1:这里是Gateway端口;\n  proxy_read_timeout 3600;\n  proxy_http_version 1.1;\n  proxy_set_header Upgrade $http_upgrade;\n  proxy_set_header Connection \"Upgrade\";\n  proxy_set_header X-Real-IP $remote_addr;\n}\n```\n\n## 唯一配置文件\n\n`/config/gateway_worker.php`\n\n配置文件内，有详细的注释，可以帮助您理解各种使用场景下的配置。\n\n## 最佳实践\n\n通过 `.env` 设置环境变量，以供 `/config/gateway_worker.php` 使用，配置项见下述。\n\n## Env环境变量\n\n```env\nGATEWAY_SECRET_KEY = \nGATEWAY_REGISTER_LISTEN_ADDRESS = 127.0.0.1\nGATEWAY_REGISTER_ADDRESS = 127.0.0.1\nGATEWAY_REGISTER_PORT = 1236\nGATEWAY_LOCAL_IP = 127.0.0.1\nGATEWAY_START_PORT = 4000\n```\n\n## 应用场景举例\n\n[与ThinkPHP等框架结合](https://www.workerman.net/doc/gateway-worker/work-with-other-frameworks.html)\n\n## 与webman结合\n\n以提供websocket服务为例：\n\n### 1. 进程启动，返回连接参数\n\n进程启动后 `\\Ledc\\GatewayWorker\\EventHandler::onConnect`，服务会返回 `{\"event\":\"init\",\"client_id\":\"7f0000010fa0000000a2\",\"timestamp\":1757583080,\"auth\":\"21826584bdaf086f7e9910baac281eef\"}`\n\n### 2. 前端页面转发 上述参数到后端webman接口\n\n### 3. webman控制器接收到参数，验证用户登陆状态\n\n验证通过后，调用 `\\Ledc\\GatewayWorker\\EventHandler::bindUid` 绑定用户。\n\n或者，调用 `\\Ledc\\GatewayWorker\\EventHandler::joinGroup` 把客户端加入群组。\n\n上述，也可同时操作（看业务需要）。\n\n### 4. webman后端注册事件监听\n\n#### 配置文件监听\n\n编辑 `/config/event.php`，根据需要监听 `\\Ledc\\GatewayWorker\\EventEnums` 内列举的枚举事件\n\n#### 或者在Bootstrap监听\n\n参考 [业务初始化](https://www.workerman.net/doc/webman/others/bootstrap.html)\n\n比如你监听 前端 websocket连接的 `ping` 事件\n\n只需要在 `Bootstrap` 内添加：\n\n```php\n// 监听ping事件\n\\Ledc\\GatewayWorker\\EventEnums::onPing-\u003eon(function (string $client_id) {\n    // 你的业务代码\n});\n```\n\n也可以继续注册其他事件的监听，事件调用时机或参数，请参考 `\\Ledc\\GatewayWorker\\EventHandler`。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fledccn%2Fgateway-worker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fledccn%2Fgateway-worker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fledccn%2Fgateway-worker/lists"}