{"id":21726183,"url":"https://github.com/zgldh/workerboy","last_synced_at":"2025-06-16T02:06:35.123Z","repository":{"id":30358179,"uuid":"33910659","full_name":"zgldh/workerboy","owner":"zgldh","description":"Workerman3 for Laravel5","archived":false,"fork":false,"pushed_at":"2017-03-17T05:12:18.000Z","size":111,"stargazers_count":45,"open_issues_count":1,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T23:03:05.680Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zgldh.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":"2015-04-14T04:25:40.000Z","updated_at":"2023-08-26T14:44:21.000Z","dependencies_parsed_at":"2022-07-31T09:47:58.998Z","dependency_job_id":null,"html_url":"https://github.com/zgldh/workerboy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/zgldh/workerboy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgldh%2Fworkerboy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgldh%2Fworkerboy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgldh%2Fworkerboy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgldh%2Fworkerboy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zgldh","download_url":"https://codeload.github.com/zgldh/workerboy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zgldh%2Fworkerboy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260083863,"owners_count":22956408,"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-26T03:22:39.793Z","updated_at":"2025-06-16T02:06:35.101Z","avatar_url":"https://github.com/zgldh.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"请移步这里： http://workerman.net/gatewaydoc/work-with-other-frameworks/README.html\n\n水平有限，workerboy坑了\nThis package is deprecated.\n\n\n# Workerboy\n\nWorkerboy是Workerman3在Laravel5下的封装。\n\n装上以后就可以用Laravel的artisan命令来管理workerman了。\n\n## 依赖\n PHP 5.4\n\n 本产品依赖 PHP的\"ext-sockets\" 扩展。Windows下就别想了。\n\n 为了提升性能，推荐安装\"ext-libevent\" 扩展。看这里： http://www.workerman.net/install \n\n## 更新\n - v0.15 增加了“凭证”机制，用于同步Web服务器用户ID和Socket服务器ClientId。具体请查看下面[凭证机制](#凭证机制)说明。\n - v0.14 修复了多workerman应用间互相冲突的bug。 请注意新的config格式： ```/vendor/zgldh/workerboy/config/workerboy.php```\n请注意每个应用的```start.php```里面需要给每个worker配置config。具体请看应用模板文件```/vendor/zgldh/workerboy/templates/\\GatewayBusinessWorkerApplication/start.php```\n\n## 用法\n\n 1. `composer require zgldh/workerboy`。\n 2. 在`config\\app.php`的 `providers`数组添加 `zgldh\\workerboy\\WorkerBoyServiceProvider`。\n 3. `php artisan vendor:publish` 将workerboy.php配置项输出到config目录下。\n 4. `php artisan workerboy:create MyApplication` 新建一个Workerman3应用。\n 5. 编辑`Event.php`文件。写业务逻辑。\n 6. 在`config/workerboy.php`的`applications`数组里增加刚刚添加的Workerman3应用。\n 7. `php artisan workerboy:start --deamon` 启动所有Workerman3应用。\n\n\n## 命令\n\n - ### create\n  `workerboy:create ApplicationName` 创建一个Workerman3应用，默认是Gateway/BusinessWorker模式。\n  `workerboy:create ApplicationName --worker-only` 使用纯Worker模式创建一个Workerman3应用。\n\n - ### start\n  `workerboy:start` 启动Workerman3所有的应用。默认是调试模式。\n  `workerboy:start --deamon` 以daemon方式启动。\n\n - ### stop\n  `workerboy:stop` 停止系统。\n\n - ### restart\n  `workerboy:stop` 重启系统。\n\n - ### reload\n  `workerboy:reload` 平滑重启。\n\n - ### status\n  `workerboy:status` 查看状态。\n\n具体请看： http://doc3.workerman.net/install/start-and-stop.html\n\n\n## 凭证机制\n\n  开发者常遇痛点：WebSocket连上了，如何告诉Socket服务器当前连上的是Web服务器里的哪个用户呢？ 直接在连接的时候写上UserId？那太不保险了。\n  Workerboy为了解决该问题而产生了凭证机制，用于同步Web服务器用户ID和Socket服务器ClientId。\n  \n  一共3步：\n  \n  1. 在做WebSocket的页面输出一个凭证：\n  \n    ```javascript\n    \u003cscript\u003e\n        var WORKERBOY_CREDENTIAL = \u003c?php echo json_encode(\\zgldh\\workerboy\\WorkerBoy::getInstance()-\u003eoutputCredential()); ?\u003e;\n    \u003c/script\u003e\n    ```\n  2. 在WebSocket连接时将凭证传过去：\n  \n    ```javascript\n    var ws = new WebSocket('ws://' + window.location.host + ':8685');\n    ws.onopen = function () {\n        ws.send(JSON.stringify({\n            type                : \"login\",\n            workerboy_credential: WORKERBOY_CREDENTIAL\n        }));\n    };\n    ```\n  3. 在Event.php里面验证凭证：\n  \n    ```php\n    $workerBoy = WorkerBoy::getInstance();\n    $credential = @$message_data['workerboy_credential'];\n    $userId = $workerBoy-\u003evalidateCredential($credential);\n    ```    \n    这样你就拿到了当前Socket连接用户在Web服务器里的UserId了。\n   \n   凭证机制默认使用Laravel的Session进行储存，你可以修改`config/workerboy.php`的`credential_processor`项来自定义凭证机制。\n\n## Workerman 3.0 \n\nGitHub: [https://github.com/walkor/workerman](https://github.com/walkor/workerman)\n\nHome page:[http://www.workerman.net](http://www.workerman.net)\n\nDocumentation:[http://doc3.workerman.net](http://doc3.workerman.net)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgldh%2Fworkerboy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzgldh%2Fworkerboy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzgldh%2Fworkerboy/lists"}