PHPackages                             imiphp/imi-hprose - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. imiphp/imi-hprose

ActiveLibrary[Framework](/categories/framework)

imiphp/imi-hprose
=================

在 imi 框架中集成 Hprose 服务开发

v2.1.11(2y ago)627MulanPSL-2.0PHP

Since Dec 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/imiphp/imi-hprose)[ Packagist](https://packagist.org/packages/imiphp/imi-hprose)[ RSS](/packages/imiphp-imi-hprose/feed)WikiDiscussions 2.0 Synced today

READMEChangelog (10)Dependencies (4)Versions (35)Used By (0)

imi-hprose
==========

[](#imi-hprose)

[![Latest Version](https://camo.githubusercontent.com/979ad5a89f8bc627ba82be57dd1c1c237a926bebf5c2f617d3fe42b9d9a81cec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696d697068702f696d692d6870726f73652e737667)](https://packagist.org/packages/imiphp/imi-hprose)[![Php Version](https://camo.githubusercontent.com/4a5c2ab20974058a8bab53ecb30ac4c2e6bb961df6229b7386fdc097ab53dfa8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e342d627269676874677265656e2e737667)](https://secure.php.net/)[![Swoole Version](https://camo.githubusercontent.com/f077644cadc3b88104d75a54818d0e1462f910dc6d6dfd9939ea295fb11b4e2b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73776f6f6c652d2533453d342e312e302d627269676874677265656e2e737667)](https://github.com/swoole/swoole-src)[![IMI License](https://camo.githubusercontent.com/7384c4b39e4421520e1a892cb4e67908cb819287c63ce137e5b0027365e2a168/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f696d697068702f696d692d6870726f73652e737667)](https://github.com/imiphp/imi-hprose/blob/master/LICENSE)

介绍
--

[](#介绍)

在 imi 框架中集成 Hprose 服务开发，目前支持`TCP`、`Unix Socket`协议。

未来将实现：中间件、过滤器、`Http` 协议、`WebSocket` 协议……

> 本仓库仅用于浏览，不接受 issue 和 Pull Requests，请前往：

Composer
--------

[](#composer)

本项目可以使用composer安装，遵循psr-4自动加载规则，在你的 `composer.json` 中加入下面的内容:

```
{
    "require": {
        "imiphp/imi-hprose": "~2.0.0"
    }
}
```

然后执行 `composer update` 安装。

服务端
---

[](#服务端)

在项目 `config/config.php` 中配置：

```
[
    'components'    =>  [
        // 引入RPC组件以及本组件
        'Rpc'       =>  'Imi\Rpc',
        'Hprose'    =>  'Imi\Hprose',
    ],
]
```

如果你用主服务器：

```
[
    // 主服务器配置
    'mainServer' => [
        'namespace'    =>	'XXX\MainServer', // 你的命名空间
		'type'		=>	'Hprose', // 必须设为 Hprose
		'port'		=>	8080,
	],
]
```

如果你用子服务器：

```
[
    // 子服务器（端口监听）配置
	'subServers'		=>	[
		// 子服务器名
		'XXX'	=>	[
			'namespace'	=>	'XXX\Hprose', // 你的命名空间
			'type'		=>	'Hprose', // 必须设为 Hprose
			'port'		=>	50001,
		]
	],
]
```

### 控制器基类

[](#控制器基类)

`Imi\Rpc\Controller\RpcController`

### 控制器注解

[](#控制器注解)

`\Imi\Rpc\Route\Annotation\RpcController`

用法：

`@RpcController`

别名前缀：`@RpcController('a_b_')`

### 动作注解

[](#动作注解)

`\Imi\Rpc\Route\Annotation\RpcAction`

无参

### 路由注解

[](#路由注解)

`\Imi\Hprose\Route\Annotation\HproseRoute`

参数：

- `name` 路由名称规则。一般也是方法名，如果设置了别名，则最终为别名+方法名
- `mode` 该设置表示该服务函数返回的结果类型，具体值请参考 Hprose 文档
- `simple` 该设置表示本服务函数所返回的结果是否为简单数据。默认值为 false。
- `oneway` 该设置表示本服务函数是否不需要等待返回值。当该设置为 true 时，调用会异步开始，并且不等待结果，立即返回 null 给客户端。默认值为 false。
- `async` 该设置表示本服务函数是否为异步函数，异步函数的最后一个参数是一个回调函数，用户需要在异步函数中调用该回调方法来传回返回值
- `passContext` 该属性为 boolean 类型，默认值为 false。具体请参考 Hprose 文档

> Hprose 文档参考：[https://github.com/hprose/hprose-php/wiki/06-Hprose-服务器#addfunction-%E6%96%B9%E6%B3%95](https://github.com/hprose/hprose-php/wiki/06-Hprose-%E6%9C%8D%E5%8A%A1%E5%99%A8#addfunction-%E6%96%B9%E6%B3%95)

客户端
---

[](#客户端)

### 连接池配置

[](#连接池配置)

```
[
	'pools'	=>	[
		'连接池名'	=>	[
			'sync'	=>	[
				'pool'	=>	[
					'class'		=>	\Imi\Rpc\Client\Pool\RpcClientSyncPool::class,
					'config'	=>	[
						// 连接池通用，查阅文档
					],
				],
				'resource'	=>	[
					'clientClass'	=>	\Imi\Hprose\Client\HproseSocketClient::class,
					'uris'	=>	'tcp://127.0.0.1:50001', // 连接地址
					// 其它配置
				]
			],
			'async'	=>	[
				'pool'	=>	[
					'class'		=>	\Imi\Rpc\Client\Pool\RpcClientCoroutinePool::class,
					'config'	=>	[
						// 连接池通用，查阅文档
					],
				],
				'resource'	=>	[
					'clientClass'	=>	\Imi\Hprose\Client\HproseSocketClient::class,
					'uris'	=>	'tcp://127.0.0.1:50001', // 连接地址
					// 其它配置
				]
			],
		],
	],
	'rpc'	=>	[
		'defaultPool'	=>	'连接池名', // 默认连接池名
	],
]
```

### 客户端调用

[](#客户端调用)

代码调用：

```
\Imi\Rpc\Client\Pool\RpcClientPool::getService('服务名')->方法名(参数);
```

注解调用：

```
class Test
{
	/**
	 * @RpcClient()
	 *
	 * @var \Imi\Rpc\Client\IRpcClient
	 */
	protected $rpcClient;

	/**
	 * @RpcService(serviceName="服务名")
	 *
	 * @var \Imi\Rpc\Client\IService
	 */
	protected $xxxRpc;

	public function aaa()
	{
		// 方法一
		$this->rpcClient->getService('服务名')->方法名(参数);

		// 方法二
		$this->xxxRpc->方法名(参数);
	}
}
```

免费技术支持
------

[](#免费技术支持)

QQ群：17916227 [![点击加群](https://camo.githubusercontent.com/75b53e353bb9e5064662e185a6d39f4bb88c4e45bd3a1240ddf599525edb6afa/68747470733a2f2f7075622e69647171696d672e636f6d2f7770612f696d616765732f67726f75702e706e67 "点击加群")](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)，如有问题会有人解答和修复。

运行环境
----

[](#运行环境)

- [PHP](https://php.net/) &gt;= 7.4
- [Composer](https://getcomposer.org/) &gt;= 2.0
- [Swoole](https://www.swoole.com/) &gt;= 4.1.0

版权信息
----

[](#版权信息)

`imi-hprose` 遵循 MIT 开源协议发布，并提供免费使用。

捐赠
--

[](#捐赠)

[![](https://raw.githubusercontent.com/imiphp/imi/2.0/res/pay.png)](https://raw.githubusercontent.com/imiphp/imi/2.0/res/pay.png)

开源不求盈利，多少都是心意，生活不易，随缘随缘……

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 96.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~51 days

Recently: every ~43 days

Total

35

Last Release

937d ago

Major Versions

v1.2.2 → v2.0.02021-08-20

v1.2.3 → v2.0.32021-11-05

v2.1.11 → 3.0.x-dev2023-10-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f917bb42280d114c53cebadc2942a13ee03abe14971089f88895e266d637169?d=identicon)[Yurunsoft](/maintainers/Yurunsoft)

---

Top Contributors

[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (55 commits)")[![NHZEX](https://avatars.githubusercontent.com/u/14545600?v=4)](https://github.com/NHZEX "NHZEX (2 commits)")

### Embed Badge

![Health badge](/badges/imiphp-imi-hprose/health.svg)

```
[![Health](https://phpackages.com/badges/imiphp-imi-hprose/health.svg)](https://phpackages.com/packages/imiphp-imi-hprose)
```

###  Alternatives

[laravel/telescope

An elegant debug assistant for the Laravel framework.

5.2k67.8M192](/packages/laravel-telescope)[nolimits4web/swiper

Most modern mobile touch slider and framework with hardware accelerated transitions

41.8k177.2k1](/packages/nolimits4web-swiper)[laravel/prompts

Add beautiful and user-friendly forms to your command-line applications.

708181.8M596](/packages/laravel-prompts)[cakephp/chronos

A simple API extension for DateTime.

1.4k47.7M121](/packages/cakephp-chronos)[laravel/pail

Easily delve into your Laravel application's log files directly from the command line.

91245.3M590](/packages/laravel-pail)[nette/bootstrap

🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.

68435.8M592](/packages/nette-bootstrap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
