{"id":36988414,"url":"https://github.com/xiaochengfu/websocket-swoole","last_synced_at":"2026-01-13T23:25:47.256Z","repository":{"id":57083967,"uuid":"131379720","full_name":"xiaochengfu/websocket-swoole","owner":"xiaochengfu","description":"基于swoole实现websocket实时通信，推送服务,适用thinkphp/yii2/laravel等框架","archived":false,"fork":false,"pushed_at":"2019-12-30T03:00:32.000Z","size":29,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-26T21:50:33.064Z","etag":null,"topics":["laravel-websocket","php-websocket","php-websocket-server","thinkphp-websocket","yii2-websocket"],"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/xiaochengfu.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":"2018-04-28T06:24:02.000Z","updated_at":"2022-04-25T07:42:29.000Z","dependencies_parsed_at":"2022-08-24T14:56:39.272Z","dependency_job_id":null,"html_url":"https://github.com/xiaochengfu/websocket-swoole","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/xiaochengfu/websocket-swoole","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaochengfu%2Fwebsocket-swoole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaochengfu%2Fwebsocket-swoole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaochengfu%2Fwebsocket-swoole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaochengfu%2Fwebsocket-swoole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiaochengfu","download_url":"https://codeload.github.com/xiaochengfu/websocket-swoole/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaochengfu%2Fwebsocket-swoole/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28403795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-13T21:51:37.118Z","status":"ssl_error","status_checked_at":"2026-01-13T21:45:14.585Z","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":["laravel-websocket","php-websocket","php-websocket-server","thinkphp-websocket","yii2-websocket"],"created_at":"2026-01-13T23:25:46.559Z","updated_at":"2026-01-13T23:25:47.250Z","avatar_url":"https://github.com/xiaochengfu.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websocket-Swoole php框架扩展\n\n\u003e ## 扩展说明\n\n基于swoole开发的websocket实时推送、主动推送、长连接扩展，应用于php的各类框架，如thinkphp,yii2,laravel等\n\n\u003e ## 如何使用\n\n## 安装\n\n```php\ncomposer require xiaochengfu/swoole-websocket\n```\n\n## 配置\n\n1.将params_swoole.php.default配置文件放到你框架配置文件夹下\n推荐放到config下：\n```sh\nlaravel、thinkphp5/6放到config目录下\n\nyii2放到common/config目录下\n\n```\n2.修改配置文件\n\n如何修改，配置文件中有具体说明\n\n## 启动\n\n根据每个框架的自定义命令，设置对应的指令即可，以启动为例\n\n```php\n$setting = config('params.swoole');//框架获取配置的方法，各有不同\n\n$swoole = new SwooleService($setting);\n$swoole-\u003eserviceStart();\n```\n扩展支持\n\na.启动服务 serviceStart\n\nb.查看服务状态 serviceStats\n\nc.查看进程列表 serviceList\n\nd.停止服务 serviceStop\n\n## 场景测试\n\n1.连接socket\n\n访问`http://www.websocket-test.com`，输入ip:9512，进行连接测试\n\n2.测试推送\n\n推送通过http请求触发，在你要触发推送的action中，添加\n```php\n$swoole = new \\xiaochengfu\\swoole\\Swoole(config('params.swoole'));\n$swoole-\u003epushMsg(1,['hello','world']);\n\n//注意pushMsg($fd,$data)\n//fd 这里可用刚连接的客户端1\n//data 类型为数组\n\n```\n正确的话，你将在刚连接的浏览器客户端中接收到推送消息\n\n3. 测试实时消息通信\n\n这里采用callback回调的方式，可灵活的嵌入逻辑，只需要把`SwooleCallback.php`\n文件放到vendor外的任何地方，通过修改命名空间来访问，这里仅把SwooleCallback.php文件当作测试回调文件!\n\n客户端发送消息格式如下：\n```json\n{\"data\":{\"namespace\":\"xiaochengfu\\\\swoole\\\\SwooleCallback\",\"function\":\"test\",\"params\":{\"a\":1}}}\n```\n---敲黑板---\n\na.发送的消息必须为字符串\n\nb.格式说明\n\n`namespace` 为回调文件的名字空间\n\n`function` 为回调文件内的方法，必须为静态方法\n\n`params` 为方法的参数\n\n正确的话，socket客户端将立即收到服务端返回的消息\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaochengfu%2Fwebsocket-swoole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiaochengfu%2Fwebsocket-swoole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaochengfu%2Fwebsocket-swoole/lists"}