{"id":18345852,"url":"https://github.com/hyperf/rpc-multiplex","last_synced_at":"2025-08-11T17:42:32.626Z","repository":{"id":44794139,"uuid":"381255873","full_name":"hyperf/rpc-multiplex","owner":"hyperf","description":"[READ ONLY] Rpc for multiplexing connection","archived":false,"fork":false,"pushed_at":"2024-04-26T02:43:12.000Z","size":53,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-26T03:35:20.735Z","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/hyperf.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},"funding":{"open_collective":"hyperf","custom":"https://hyperf.wiki/#/zh-cn/donate"}},"created_at":"2021-06-29T06:00:55.000Z","updated_at":"2024-06-20T04:00:26.278Z","dependencies_parsed_at":"2023-11-22T07:29:52.554Z","dependency_job_id":"c262d69b-a7a8-400e-a927-201332fdb8fe","html_url":"https://github.com/hyperf/rpc-multiplex","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf%2Frpc-multiplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf%2Frpc-multiplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf%2Frpc-multiplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyperf%2Frpc-multiplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyperf","download_url":"https://codeload.github.com/hyperf/rpc-multiplex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457516,"owners_count":20941902,"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-05T21:09:45.760Z","updated_at":"2025-04-06T08:32:22.388Z","avatar_url":"https://github.com/hyperf.png","language":"PHP","readme":"# Rpc for multiplexing connection\n\n[![PHPUnit](https://github.com/hyperf/rpc-multiplex-incubator/actions/workflows/test.yml/badge.svg)](https://github.com/hyperf/rpc-multiplex-incubator/actions/workflows/test.yml)\n\n## 安装\n\n```\ncomposer require hyperf/rpc-multiplex\n```\n\n## Server 配置\n\n修改 `config/autoload/server.php` 配置文件\n\n\u003e 删除不相干配置\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nuse Hyperf\\Server\\Event;\nuse Hyperf\\Server\\Server;\n\nreturn [\n    'servers' =\u003e [\n        [\n            'name' =\u003e 'rpc',\n            'type' =\u003e Server::SERVER_BASE,\n            'host' =\u003e '0.0.0.0',\n            'port' =\u003e 9502,\n            'sock_type' =\u003e SWOOLE_SOCK_TCP,\n            'callbacks' =\u003e [\n                Event::ON_RECEIVE =\u003e [Hyperf\\RpcMultiplex\\TcpServer::class, 'onReceive'],\n            ],\n            'settings' =\u003e [\n                'open_length_check' =\u003e true,\n                'package_length_type' =\u003e 'N',\n                'package_length_offset' =\u003e 0,\n                'package_body_offset' =\u003e 4,\n                'package_max_length' =\u003e 1024 * 1024 * 2,\n            ],\n        ],\n    ],\n];\n\n```\n\n创建 `RpcService`\n\n```php\n\u003c?php\n\nnamespace App\\RPC;\n\nuse App\\JsonRpc\\CalculatorServiceInterface;\nuse Hyperf\\RpcMultiplex\\Constant;\nuse Hyperf\\RpcServer\\Annotation\\RpcService;\n\n/**\n * @RpcService(name=\"CalculatorService\", server=\"rpc\", protocol=Constant::PROTOCOL_DEFAULT)\n */\nclass CalculatorService implements CalculatorServiceInterface\n{\n}\n\n```\n\n## 客户端配置\n\n修改 `config/autoload/services.php` 配置文件\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nreturn [\n    'consumers' =\u003e [\n        [\n            'name' =\u003e 'CalculatorService',\n            'service' =\u003e App\\JsonRpc\\CalculatorServiceInterface::class,\n            'id' =\u003e App\\JsonRpc\\CalculatorServiceInterface::class,\n            'protocol' =\u003e Hyperf\\RpcMultiplex\\Constant::PROTOCOL_DEFAULT,\n            'load_balancer' =\u003e 'random',\n            'nodes' =\u003e [\n                ['host' =\u003e '127.0.0.1', 'port' =\u003e 9502],\n            ],\n            'options' =\u003e [\n                'connect_timeout' =\u003e 5.0,\n                'recv_timeout' =\u003e 5.0,\n                'settings' =\u003e [\n                    // 包体最大值，若小于 Server 返回的数据大小，则会抛出异常，故尽量控制包体大小\n                    'package_max_length' =\u003e 1024 * 1024 * 2,\n                ],\n                // 重试次数，默认值为 2\n                'retry_count' =\u003e 2,\n                // 重试间隔，毫秒\n                'retry_interval' =\u003e 100,\n                // 多路复用客户端数量\n                'client_count' =\u003e 4,\n                // 心跳间隔 非 numeric 表示不开启心跳\n                'heartbeat' =\u003e 30,\n            ],\n        ],\n    ],\n];\n\n```\n\n\n","funding_links":["https://opencollective.com/hyperf","https://hyperf.wiki/#/zh-cn/donate"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf%2Frpc-multiplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyperf%2Frpc-multiplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyperf%2Frpc-multiplex/lists"}