PHPackages                             panus/php-thrift-swoole - 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. panus/php-thrift-swoole

ActiveLibrary

panus/php-thrift-swoole
=======================

基于Swoole的Thrift Server实现

v0.1.7(8y ago)93302MITPHPPHP &gt;=5.4.0

Since Apr 2Pushed 7y ago2 watchersCompare

[ Source](https://github.com/fathpanus/php-thrift-swoole)[ Packagist](https://packagist.org/packages/panus/php-thrift-swoole)[ RSS](/packages/panus-php-thrift-swoole/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (0)

基于Swoole的Thrift Server实现
========================

[](#基于swoole的thrift-server实现)

安装
--

[](#安装)

```
composer require panus/php-thrift-swoole

```

服务端示例
-----

[](#服务端示例)

- 生成服务端代码

```
thrift --gen php:server,psr4 order.thrift

```

- 业务层自行去实现生成的接口

```
$service = new OrderServiceImpl();
$processor = new OrderServiceProcessor($service);

//swooler_server 里的配置选项参数，worker_num根据实际调用情况调节
$setting = [
    'worker_num' => 4,
    'log_file' => __DIR__.'/swoole.log',
    'pid_file' => __DIR__.'/thrift.pid',
];
$socket_tranport = new \SwooleThrift\TSwooleServerTransport('0.0.0.0', 8192, $setting);
$out_factory = $in_factory = new \Thrift\Factory\TTransportFactory();
$out_protocol = $in_protocol = new \Thrift\Factory\TBinaryProtocolFactory();

$server = new \SwooleThrift\TSwooleServer($processor, $socket_tranport, $in_factory, $out_factory, $in_protocol, $out_protocol);
$server->serve();

```

客户端示例
-----

[](#客户端示例)

```
$socket = new \Thrift\Transport\TSocket('192.168.0.101', 8100);
$transport = new \Thrift\Transport\TFramedTransport($socket);
$protocol = new \Thrift\Protocol\TBinaryProtocol($transport);
$transport->open();

$client = new OrderServiceClient($protocol);
$client->implMethod(...);

$transport->close();

```

开启thrift\_protocol扩展（可选）
------------------------

[](#开启thrift_protocol扩展可选)

```
cd /thrift_root/lib/php/src/ext/thrift_protocol
/php_path/bin/phpize
./configure --with-php-config=/php_path/bin/php-config
make
make install
echo "extension=thrift_protocol.so" >> /path/php.ini

```

后端服务负载均衡
--------

[](#后端服务负载均衡)

- nginx从1.9.0后引入模块ngx\_stream\_core\_module，模块默认是没有开启的，编译时开启 --with-stream

```
http {
  ...
}
stream {
    upstream thrift {
        server 127.0.0.1:8192 weight=1;
        #server backend1:9000 weight=5;
    }
    server {
        listen 8100;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass thrift;
    }
}

```

进程控制
----

[](#进程控制)

- 关闭服务器： `kill -TERM {masterPid}`
- 重启Worker进程： `kill -USR1 {masterPid}`
- [官方的额外说明](https://wiki.swoole.com/wiki/page/p-server/reload.html)

> 平滑重启只对onWorkerStart或onReceive等在Worker进程中include/require的PHP文件有效，Server启动前就已经include/require的PHP文件，不能通过平滑重启重新加载 对于Server的配置即$serv-&gt;set()中传入的参数设置，必须关闭/重启整个Server才可以重新加载

Server状态参数输出
------------

[](#server状态参数输出)

- 默认绑定的本地回环地址，端口为8090,可在setting 里设置`http_server_host`和`http_server_port`，不建绑在公网ip地址上
- 响应如下，也就是`swoole_server->stats`

```
{
    "start_time": 1522580115,
    "connection_num": 2,
    "accept_count": 2,
    "close_count": 0,
    "tasking_num": 0,
    "request_count": 0,
    "worker_request_count": 0
}

```

注意事项
----

[](#注意事项)

- 由于传输层是用`TFramedTransport`，所以对应的客户端也是要采用该传输层

参考部分
----

[](#参考部分)

> [swoole/thrift-rpc-server](https://github.com/swoole/thrift-rpc-server)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~5 days

Total

2

Last Release

2953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/411a6fd18d587279a925ade3b855211510a558e3bfc2873ae721f5d27a13ee49?d=identicon)[panus](/maintainers/panus)

---

Top Contributors

[![fathpanus](https://avatars.githubusercontent.com/u/7199868?v=4)](https://github.com/fathpanus "fathpanus (28 commits)")

---

Tags

rpcswoolethrift-phpthrift-serverrpcthriftthrift swoole

### Embed Badge

![Health badge](/badges/panus-php-thrift-swoole/health.svg)

```
[![Health](https://phpackages.com/badges/panus-php-thrift-swoole/health.svg)](https://phpackages.com/packages/panus-php-thrift-swoole)
```

###  Alternatives

[apache/thrift

Apache Thrift RPC system

10.9k2.1M40](/packages/apache-thrift)[grpc/grpc

gRPC library for PHP

507116.6M180](/packages/grpc-grpc)[sajya/server

Easy implementation of the JSON-RPC 2.0 server for the Laravel framework.

2391.9M4](/packages/sajya-server)[lstrojny/fxmlrpc

Fast and tiny XML/RPC client with bridges for various HTTP clients

1425.4M30](/packages/lstrojny-fxmlrpc)[datto/json-rpc

Fully unit-tested JSON-RPC 2.0 for PHP

1951.3M14](/packages/datto-json-rpc)[twirp/twirp

PHP port of Twitch's Twirp RPC framework

1591.0M5](/packages/twirp-twirp)

PHPackages © 2026

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