{"id":27349503,"url":"https://github.com/cloudtay/ripple-rpc","last_synced_at":"2026-02-11T04:31:44.046Z","repository":{"id":276921447,"uuid":"930759950","full_name":"cloudtay/ripple-rpc","owner":"cloudtay","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-11T10:15:43.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-18T12:34:25.110Z","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/cloudtay.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-11T06:55:34.000Z","updated_at":"2025-02-11T10:15:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"206b569c-2a14-4bde-8be2-8a0c6910dca9","html_url":"https://github.com/cloudtay/ripple-rpc","commit_stats":null,"previous_names":["cloudtay/ripple-rpc"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cloudtay/ripple-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudtay%2Fripple-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudtay%2Fripple-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudtay%2Fripple-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudtay%2Fripple-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloudtay","download_url":"https://codeload.github.com/cloudtay/ripple-rpc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloudtay%2Fripple-rpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29327091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"last_error":"SSL_read: 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":"2025-04-12T19:17:40.458Z","updated_at":"2026-02-11T04:31:44.041Z","avatar_url":"https://github.com/cloudtay.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 简介\n\n本项目是一个基于`ripple`引擎实现的PHP服务器,支持`HTTP`和`WebSocket`通信方式\n\n### 特性\n\n* 支持`JSON-RPC 2.0`\n* 同时支持 `HTTP` 与 `WebSocket` 协议\n* 可自定义路由\n* 支持中间件\n* 错误处理与异常捕获\n\n## 快速开始\n\n### 安装\n\n```bash\ncomposer require cloudtay/ripple-rpc\n```\n\n### 创建服务器实例\n\n```php\n\u003c?php declare(strict_types=1);\ninclude 'vendor/autoload.php';\n\nuse Ripple\\Coroutine\\Context;\nuse Ripple\\RPC\\Json\\Server;\n\nuse function Co\\wait;\n\n$server = new Server();\n\n// 绑定服务地址\n$server-\u003ebind('http://0.0.0.0:8000/jsonrpc');\n\n// 或者绑定WebSocket服务地址\n$server-\u003ebind('ws://0.0.0.0:9000');\n\n// 注册路由\n$server-\u003eroute('sum', static function (int $a, int $b) {\n    return $a + $b;\n});\n\n// 支持callable数组\n$server-\u003eroute('createFromFormat', [DateTime::class, 'createFromFormat']);\n$server-\u003erun();\n\n// 添加中间件\n$server-\u003emiddleware(static function ($next) {\n    // 通过上下文获取请求信息(仅在HTTP协议下有效)\n    $request = Context::get('request');\n\n    // 通过上下文获取连接信息(仅在WebSocket协议下有效)\n    $connection = Context::get('connection');\n\n    // 通过上下文获取请求JSON\n    $requestJson = Context::get('requestJson');\n\n    if (\\rand(0, 1) === 1) {\n        // 自定义错误处理\n        //        throw new JsonException([\n        //            'code'    =\u003e -32603,\n        //            'message' =\u003e '服务器内部错误',\n        //        ]);\n    }\n\n    return $next();\n});\n\n// 运行服务器\n$server-\u003erun();\n\n// 等待协程结束\nwait();\n```\n\n### 客户端调用\n\n```php\n\u003c?php declare(strict_types=1);\ninclude 'vendor/autoload.php';\n\nuse Ripple\\RPC\\Json\\Client;\n\n$result = Client::call('http://127.0.0.1:8000/jsonrpc', 'sum', [1, 2]);\necho $result, \\PHP_EOL; // 3\n\n\n$json = Client::request('http://127.0.0.1:8000/jsonrpc', 'sum', [1, 2], 'id');\necho $json, \\PHP_EOL; // {\"jsonrpc\":\"2.0\",\"result\":3,\"id\":\"id\"}\n```\n\n### 附 `JSON-RPC2.0API` 规范\n\n#### 请求格式\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"method\": \"sum\",\n  \"params\": [\n    2,\n    3\n  ],\n  \"id\": 1\n}\n```\n\n#### 响应格式\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"result\": 5,\n  \"id\": 1\n}\n```\n\n#### 错误响应示例\n\n```json\n{\n  \"jsonrpc\": \"2.0\",\n  \"error\": {\n    \"code\": -32601,\n    \"message\": \"Method not found\"\n  },\n  \"id\": 1\n}\n```\n\n### 错误代码表\n\n| 错误码              | 错误信息             | 描述      |\n|------------------|------------------|---------|\n| -32700           | Parse error      | 无效的JSON |\n| -32600           | Invalid Request  | 无效的请求   |\n| -32601           | Method not found | 方法不存在   |\n| -32602           | Invalid params   | 无效的参数   |\n| -32603           | Internal error   | 内部错误    |\n| -32000 to -32099 | Server error     | 服务器错误   |\n\n## 许可证\n\n本项目基于MIT许可证发布\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudtay%2Fripple-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloudtay%2Fripple-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloudtay%2Fripple-rpc/lists"}