{"id":19756817,"url":"https://github.com/imiphp/imi-hprose","last_synced_at":"2025-10-08T12:46:45.180Z","repository":{"id":52214656,"uuid":"163150327","full_name":"imiphp/imi-hprose","owner":"imiphp","description":"在 imi 框架中集成 Hprose 服务开发。QQ群：17916227","archived":false,"fork":false,"pushed_at":"2023-10-18T05:09:13.000Z","size":190,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"2.0","last_synced_at":"2025-06-30T12:44:54.134Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.imiphp.com/","language":"PHP","has_issues":false,"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/imiphp.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}},"created_at":"2018-12-26T07:27:30.000Z","updated_at":"2024-12-16T03:20:21.000Z","dependencies_parsed_at":"2023-01-22T04:15:10.085Z","dependency_job_id":"d7a872aa-7ac8-4002-86db-8193561ee3eb","html_url":"https://github.com/imiphp/imi-hprose","commit_stats":{"total_commits":55,"total_committers":2,"mean_commits":27.5,"dds":"0.036363636363636376","last_synced_commit":"b08078c0c3ecdc881ea8a36b068587072208f14a"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"purl":"pkg:github/imiphp/imi-hprose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imiphp%2Fimi-hprose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imiphp%2Fimi-hprose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imiphp%2Fimi-hprose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imiphp%2Fimi-hprose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imiphp","download_url":"https://codeload.github.com/imiphp/imi-hprose/tar.gz/refs/heads/2.0","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imiphp%2Fimi-hprose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278947994,"owners_count":26073740,"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-10-08T02:00:06.501Z","response_time":56,"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-12T03:17:01.496Z","updated_at":"2025-10-08T12:46:45.145Z","avatar_url":"https://github.com/imiphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imi-hprose\n\n[![Latest Version](https://img.shields.io/packagist/v/imiphp/imi-hprose.svg)](https://packagist.org/packages/imiphp/imi-hprose)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.4-brightgreen.svg)](https://secure.php.net/)\n[![Swoole Version](https://img.shields.io/badge/swoole-%3E=4.1.0-brightgreen.svg)](https://github.com/swoole/swoole-src)\n[![IMI License](https://img.shields.io/github/license/imiphp/imi-hprose.svg)](https://github.com/imiphp/imi-hprose/blob/master/LICENSE)\n\n## 介绍\n\n在 imi 框架中集成 Hprose 服务开发，目前支持`TCP`、`Unix Socket`协议。\n\n未来将实现：中间件、过滤器、`Http` 协议、`WebSocket` 协议……\n\n\u003e 本仓库仅用于浏览，不接受 issue 和 Pull Requests，请前往：\u003chttps://github.com/imiphp/imi\u003e\n\n## Composer\n\n本项目可以使用composer安装，遵循psr-4自动加载规则，在你的 `composer.json` 中加入下面的内容:\n\n```json\n{\n    \"require\": {\n        \"imiphp/imi-hprose\": \"~2.0.0\"\n    }\n}\n```\n\n然后执行 `composer update` 安装。\n\n## 服务端\n\n在项目 `config/config.php` 中配置：\n\n```php\n[\n    'components'    =\u003e  [\n        // 引入RPC组件以及本组件\n        'Rpc'       =\u003e  'Imi\\Rpc',\n        'Hprose'    =\u003e  'Imi\\Hprose',\n    ],\n]\n```\n\n如果你用主服务器：\n\n```php\n[\n    // 主服务器配置\n    'mainServer' =\u003e [\n        'namespace'    =\u003e\t'XXX\\MainServer', // 你的命名空间\n\t\t'type'\t\t=\u003e\t'Hprose', // 必须设为 Hprose\n\t\t'port'\t\t=\u003e\t8080,\n\t],\n]\n```\n\n如果你用子服务器：\n\n```php\n[\n    // 子服务器（端口监听）配置\n\t'subServers'\t\t=\u003e\t[\n\t\t// 子服务器名\n\t\t'XXX'\t=\u003e\t[\n\t\t\t'namespace'\t=\u003e\t'XXX\\Hprose', // 你的命名空间\n\t\t\t'type'\t\t=\u003e\t'Hprose', // 必须设为 Hprose\n\t\t\t'port'\t\t=\u003e\t50001,\n\t\t]\n\t],\n]\n```\n\n### 控制器基类\n\n`Imi\\Rpc\\Controller\\RpcController`\n\n### 控制器注解\n\n`\\Imi\\Rpc\\Route\\Annotation\\RpcController`\n\n用法：\n\n`@RpcController`\n\n别名前缀：`@RpcController('a_b_')`\n\n### 动作注解\n\n`\\Imi\\Rpc\\Route\\Annotation\\RpcAction`\n\n无参\n\n### 路由注解\n\n`\\Imi\\Hprose\\Route\\Annotation\\HproseRoute`\n\n参数：\n\n- `name` 路由名称规则。一般也是方法名，如果设置了别名，则最终为别名+方法名\n- `mode` 该设置表示该服务函数返回的结果类型，具体值请参考 Hprose 文档\n- `simple` 该设置表示本服务函数所返回的结果是否为简单数据。默认值为 false。\n- `oneway` 该设置表示本服务函数是否不需要等待返回值。当该设置为 true 时，调用会异步开始，并且不等待结果，立即返回 null 给客户端。默认值为 false。\n- `async` 该设置表示本服务函数是否为异步函数，异步函数的最后一个参数是一个回调函数，用户需要在异步函数中调用该回调方法来传回返回值\n- `passContext` 该属性为 boolean 类型，默认值为 false。具体请参考 Hprose 文档\n\n\u003e Hprose 文档参考：https://github.com/hprose/hprose-php/wiki/06-Hprose-服务器#addfunction-%E6%96%B9%E6%B3%95\n\n## 客户端\n\n### 连接池配置\n\n```php\n[\n\t'pools'\t=\u003e\t[\n\t\t'连接池名'\t=\u003e\t[\n\t\t\t'sync'\t=\u003e\t[\n\t\t\t\t'pool'\t=\u003e\t[\n\t\t\t\t\t'class'\t\t=\u003e\t\\Imi\\Rpc\\Client\\Pool\\RpcClientSyncPool::class,\n\t\t\t\t\t'config'\t=\u003e\t[\n\t\t\t\t\t\t// 连接池通用，查阅文档\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'resource'\t=\u003e\t[\n\t\t\t\t\t'clientClass'\t=\u003e\t\\Imi\\Hprose\\Client\\HproseSocketClient::class,\n\t\t\t\t\t'uris'\t=\u003e\t'tcp://127.0.0.1:50001', // 连接地址\n\t\t\t\t\t// 其它配置\n\t\t\t\t]\n\t\t\t],\n\t\t\t'async'\t=\u003e\t[\n\t\t\t\t'pool'\t=\u003e\t[\n\t\t\t\t\t'class'\t\t=\u003e\t\\Imi\\Rpc\\Client\\Pool\\RpcClientCoroutinePool::class,\n\t\t\t\t\t'config'\t=\u003e\t[\n\t\t\t\t\t\t// 连接池通用，查阅文档\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t'resource'\t=\u003e\t[\n\t\t\t\t\t'clientClass'\t=\u003e\t\\Imi\\Hprose\\Client\\HproseSocketClient::class,\n\t\t\t\t\t'uris'\t=\u003e\t'tcp://127.0.0.1:50001', // 连接地址\n\t\t\t\t\t// 其它配置\n\t\t\t\t]\n\t\t\t],\n\t\t],\n\t],\n\t'rpc'\t=\u003e\t[\n\t\t'defaultPool'\t=\u003e\t'连接池名', // 默认连接池名\n\t],\n]\n```\n\n### 客户端调用\n\n代码调用：\n\n```php\n\\Imi\\Rpc\\Client\\Pool\\RpcClientPool::getService('服务名')-\u003e方法名(参数);\n```\n\n注解调用：\n\n```php\nclass Test\n{\n\t/**\n\t * @RpcClient()\n\t *\n\t * @var \\Imi\\Rpc\\Client\\IRpcClient\n\t */\n\tprotected $rpcClient;\n\n\t/**\n\t * @RpcService(serviceName=\"服务名\")\n\t *\n\t * @var \\Imi\\Rpc\\Client\\IService\n\t */\n\tprotected $xxxRpc;\n\n\tpublic function aaa()\n\t{\n\t\t// 方法一\n\t\t$this-\u003erpcClient-\u003egetService('服务名')-\u003e方法名(参数);\n\n\t\t// 方法二\n\t\t$this-\u003exxxRpc-\u003e方法名(参数);\n\t}\n}\n```\n\n## 免费技术支持\n\nQQ群：17916227 [![点击加群](https://pub.idqqimg.com/wpa/images/group.png \"点击加群\")](https://jq.qq.com/?_wv=1027\u0026k=5wXf4Zq)，如有问题会有人解答和修复。\n\n## 运行环境\n\n- [PHP](https://php.net/) \u003e= 7.4\n- [Composer](https://getcomposer.org/) \u003e= 2.0\n- [Swoole](https://www.swoole.com/) \u003e= 4.1.0\n\n## 版权信息\n\n`imi-hprose` 遵循 MIT 开源协议发布，并提供免费使用。\n\n## 捐赠\n\n\u003cimg src=\"https://raw.githubusercontent.com/imiphp/imi/2.0/res/pay.png\"/\u003e\n\n开源不求盈利，多少都是心意，生活不易，随缘随缘……\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimiphp%2Fimi-hprose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimiphp%2Fimi-hprose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimiphp%2Fimi-hprose/lists"}