{"id":20441740,"url":"https://github.com/mix-php/json-rpc","last_synced_at":"2025-08-30T02:04:38.392Z","repository":{"id":57017777,"uuid":"233567330","full_name":"mix-php/json-rpc","owner":"mix-php","description":"JSON-RPC library based on Swoole coroutine, including server and client, supports both TCP and HTTP protocols","archived":false,"fork":false,"pushed_at":"2020-09-30T06:44:36.000Z","size":123,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-25T11:03:26.142Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/mix-php.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":"2020-01-13T10:14:57.000Z","updated_at":"2024-12-16T14:56:11.000Z","dependencies_parsed_at":"2022-08-22T12:00:37.857Z","dependency_job_id":null,"html_url":"https://github.com/mix-php/json-rpc","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/mix-php/json-rpc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fjson-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fjson-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fjson-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fjson-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/json-rpc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fjson-rpc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272793018,"owners_count":24993830,"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","status":"online","status_checked_at":"2025-08-30T02:00:09.474Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-11-15T09:34:31.709Z","updated_at":"2025-08-30T02:04:38.369Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mix JSON-RPC\n\n基于 Swoole 协程的 JSON-RPC 库，包含服务器、客户端，同时支持 TCP、HTTP 两种协议，并具有微服务调用功能\n\n## Usage\n\n安装：\n\n- Swoole \u003e= 4.4.4: https://wiki.swoole.com/#/environment\n\n```\ncomposer require mix/json-rpc\n```\n\n- Service\n\n首先定义一个服务\n\n```\nclass Calculator\n{\n    public const NAME = \"php.micro.jsonrpc.calculator.Calculator\";\n\n    public function Sum(int $a, int $b): int\n    {\n        return array_sum([$a, $b]);\n    }\n}\n```\n\n- Server\n\n创建服务器，并注册 Calculator 服务\n\n```\n$server  = new \\Mix\\JsonRpc\\Server('127.0.0.1', 9234);\n$class = Calculator::class;\n$server-\u003eregister($class);\n$server-\u003estart();\n```\n\n扩展 HTTP 支持\n\n```\n$http = new \\Mix\\Http\\Server\\Server('127.0.0.1', 9235);\n$http-\u003estart($server);\n```\n\n- Client 调用\n\n创建客户端\n\n```\n$dialer = new \\Mix\\JsonRpc\\Client\\Dialer();\n$conn   = $dialer-\u003edial('127.0.0.1', 9234);\n\n$request = (new \\Mix\\JsonRpc\\Factory\\RequestFactory)-\u003ecreateRequest('Calculator.Sum', [1, 3], 100001)\n$response = $conn-\u003ecall($request);\nvar_dump($response);\n```\n\n- Client 微服务调用\n\n```\n$dialer = new \\Mix\\JsonRpc\\Client\\Dialer([\n    'registry' =\u003e new \\Mix\\Micro\\Etcd\\Registry('http://127.0.0.1:2379/v3'),\n]);\n$conn   = $dialer-\u003edialFromService('php.micro.jsonrpc.calculator');\n\n$request = (new \\Mix\\JsonRpc\\Factory\\RequestFactory)-\u003ecreateRequest('Calculator.Sum', [1, 3], 100001)\n$response = $conn-\u003ecall($request);\nvar_dump($response);\n```\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fjson-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fjson-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fjson-rpc/lists"}