PHPackages                             pinguo/php-msf - 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. pinguo/php-msf

ActiveLibrary[Framework](/categories/framework)

pinguo/php-msf
==============

Pinguo Micro Service Framework For PHP

3.0.6(7y ago)1.7k4.2k316[17 issues](https://github.com/pinguo/php-msf/issues)GPLPHPPHP &gt;=7.0

Since Sep 7Pushed 7y ago139 watchersCompare

[ Source](https://github.com/pinguo/php-msf)[ Packagist](https://packagist.org/packages/pinguo/php-msf)[ Docs](https://github.com/pinguo/php-msf)[ RSS](/packages/pinguo-php-msf/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (0)

[![](./php-msf.png)](./php-msf.png)

[![](https://camo.githubusercontent.com/63eac5ca281766ac50a4d290692c9e0b840f2e4b3911f241ecb0a271f01fcf0f/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f76657273696f6e)](https://camo.githubusercontent.com/63eac5ca281766ac50a4d290692c9e0b840f2e4b3911f241ecb0a271f01fcf0f/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f76657273696f6e)[![](https://camo.githubusercontent.com/5acc5cc5d2efe35268a4744ae65b58e13b89156109b967f65d62686fefdd325a/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f646f776e6c6f616473)](https://camo.githubusercontent.com/5acc5cc5d2efe35268a4744ae65b58e13b89156109b967f65d62686fefdd325a/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f646f776e6c6f616473)[![](https://camo.githubusercontent.com/22738a52da69cc19d1a4f7ee72c0cdd843097b2137e7a8b9483760bc430bfcce/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f762f756e737461626c65)](https://camo.githubusercontent.com/22738a52da69cc19d1a4f7ee72c0cdd843097b2137e7a8b9483760bc430bfcce/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f762f756e737461626c65)[![](https://camo.githubusercontent.com/7574f8c15871a4908760580cfb7c08502db722c19919f879e41b161f235def7f/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f6c6963656e7365)](https://camo.githubusercontent.com/7574f8c15871a4908760580cfb7c08502db722c19919f879e41b161f235def7f/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f6c6963656e7365)[![](https://camo.githubusercontent.com/2218b95bdaa48af181c2ce023deef4847b876256b6d43125be695dde0b23cc09/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f636f6d706f7365726c6f636b)](https://camo.githubusercontent.com/2218b95bdaa48af181c2ce023deef4847b876256b6d43125be695dde0b23cc09/68747470733a2f2f706f7365722e707567782e6f72672f70696e67756f2f7068702d6d73662f636f6d706f7365726c6f636b)

Micro Service Framework For PHP
===============================

[](#micro-service-framework-for-php)

PHP微服务框架即“Micro Service Framework For PHP”，是[Camera360](https://www.camera360.com)社区服务器端团队基于[Swoole](http://www.swoole.com)自主研发现代化的PHP协程服务框架，简称msf或者php-msf，是[Swoole](http://www.swoole.com)的工程级企业应用框架，经受了Camera360亿级用户高并发大流量的考验。php-msf由[Camera360](https://www.camera360.com)服务器团队主导研发，会持续更新与维护，也希望有更多优秀的[Swoole](http://www.swoole.com)应用实践开发者加入。php-msf核心设计思想是采用协程、异步、并行的创新技术手段提高系统的单机吞吐能力，降低整体服务器成本。

主要特性
----

[](#主要特性)

- 精简版的MVC框架
- IO密集性业务的单机处理能力提升5-10倍
- 代码常驻内存
- 支持对象池
- 支持Redis连接池、MySQL连接池（异步与同步）
- 内置Redis Proxy，支持分布式、master-slave集群（故障自动failover与recovery）
- 内置MySQL Proxy，master-slave集群（读写分离、事务）
- 支持异步、并行
- 基于PHP Yield实现协程
- 内建http/redis/mysql/mongodb/task等协程客户端
- 纯异步的Http Server
- RPC Server/Client
- 支持命令行模式
- 支持独立进程的定时器
- 支持独立配置进程
- 支持sendfile静态文件(需配置root目录)

环境要求
----

[](#环境要求)

- Linux，FreeBSD，MacOS(有兼容问题)
- Linux内核版本2.3.32以上(支持epoll)
- PHP-7.0及以上版本（生产环境建议使用PHP-7.1）
- gcc-4.4以上版本
- [swoole-1.9.15](https://github.com/swoole/swoole-src/archive/v1.9.15.tar.gz)及以上版本（暂不支持Swoole-2.0）
- [hiredis-0.13.3](https://github.com/redis/hiredis/archive/v0.13.3.tar.gz)
- [yac](https://github.com/laruence/yac/archive/yac-2.0.2.tar.gz)
- [phpredis](http://pecl.php.net/get/redis-3.1.2.tgz)
- composer

文档
--

[](#文档)

框架手册(Gitbook): [PHP-MSF开发手册](https://pinguo.gitbooks.io/php-msf-docs/)

API Document(Rawgit): [类文档](https://cdn.rawgit.com/pinguo/php-msf-docs/4e0ed09d/api-document/index.html)

示例DEMO项目: [PHP-MSF DEMO](https://github.com/pinguo/php-msf-demo)

帮助完善文档: ，请提交PR。

交流与反馈
-----

[](#交流与反馈)

PHP-MSF#1群(QQ): 614054288

快速起步
----

[](#快速起步)

```
$>php -r "copy('https://raw.githubusercontent.com/pinguo/php-msf-docker/master/installer.php', 'installer.php');include('installer.php');" && source ~/.bashrc
```

`installer.php`会检查运行环境，根据你的自定义配置，自动创建项目模板，composer安装依赖，启动服务。如果`cdn.rawgit.com`无法访问，可以直接克隆或者下载[php-msf-docker](https://github.com/pinguo/php-msf-docker)，提取`installer.php`，然后直接运行`php installer.php`

如果一切顺利，运行到最后你将看到如下的输出：

```
[2017-09-06 16:08:34] Run composer install success
[2017-09-06 16:08:34] Congratulations, all are installed successfully!
[2017-09-06 16:08:34] You can, visit http://127.0.0.1:8990/Welcome for test
      _______                               ____
________  / /_  ____        ____ ___  _____/ __/
___/ __ \/ __ \/ __ \______/ __ `__ \/ ___/ /_
__/ /_/ / / / / /_/ /_____/ / / / / (__  ) __/
_/ .___/_/ /_/ .___/     /_/ /_/ /_/____/_/
/_/         /_/         Camera360 Open Source TM
[2017-09-06 16:08:34] Swoole  Version: 1.9.18
[2017-09-06 16:08:34] PHP     Version: 7.1.8
[2017-09-06 16:08:34] Application ENV: docker
[2017-09-06 16:08:34] Listen     Addr: 0.0.0.0
[2017-09-06 16:08:34] Listen     Port: 8990
```

访问测试：

```
$>curl http://127.0.0.1:8990/Welcome
hello world!
```

注意端口，如果你不是8990，你需要修改，然后访问测试。

标准应用结构
------

[](#标准应用结构)

```
├── app // PHP业务代码
│   ├── AppServer.php // 应用server类，可根据需求自定义
│   ├── Controllers // 控制器类目录
│   ├── Lib // 特殊逻辑处理类目录
│   ├── Models // Model类目录
│   ├── Route // 特殊路由规则类目录
│   ├── Tasks // Task类目录
│   └── Views // 视图文件目录
├── build.sh // 构建脚本（拉取docker镜像，启动容器）
├── checkstyle.sh // 代码检查脚本
├── composer.json // composer包依赖配置文件
├── config // 配置目录
├── server.php // server启动脚本
├── console.php // 命令行脚本
├── test // 单元测试目录

```

上述为基于php-msf的标准应用结构，一键安装程序installer.php会自动生成目录，用户可以根据需求创建一些自定义目录，只要符合psr4标准即可自动加载。

服务启动
----

[](#服务启动)

调试模式

```
$>./server.php start
```

Daemon模式

```
$>./server.php start -d
```

停止服务

```
$>./server.php stop
```

重启服务

```
$>./server.php restart
```

Docker
------

[](#docker)

我们制作了Docker镜像，方便Docker用户快速的安装环境，运行[PHP-MSF DEMO](https://github.com/pinguo/php-msf-demo)工程。另外期望在开发环境修改代码实时预览效果，建议使用Docker for [Mac](https://download.docker.com/mac/stable/Docker.dmg)/[Windows](https://download.docker.com/win/stable/InstallDocker.msi)桌面版。

如果是升级Docker，它会自动迁移原有的镜像和容器，请耐心等待，千万不能中途kill掉Docker进程，否则再想迁移就难了。

Docker Registry(阿里云):

- 公网地址: `docker pull registry.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker:latest`
- 经典内网: `docker pull registry-internal.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker:latest`
- VPC网络: `docker pull registry-vpc.cn-hangzhou.aliyuncs.com/pinguo-ops/php-msf-docker:latest`
- DockerHub(国外): `docker pull pinguoops/php-msf-docker`

框架定位
----

[](#框架定位)

我们专注打造稳定高性能纯异步基于HTTP的微服务框架，作为nginx+php-fpm的替代技术栈实现架构的微服务化;而Tcp/WebSocket Server将作为插件的形势支持，或者作为其他独立的开源项目。

对于小型团队或者业务系统我们建议还是采用传统的nginx+php-fpm技术栈，对于成本和性能来说没有瓶颈，也就完全没有必要引入全新的技术栈。

对于大中型团队或者业务系统，处在服务治理或者服务化演进的重要阶段，php-msf是可选方案之一。

对于庞大的PHP应用集群，想要大幅节约服务器成本，提升服务性能，php-msf是可选方案之一。

对于聚合服务，比如大型的网站首页，想要通过服务器端聚合内容整合数据，php-msf是可选方案之一。

手工安装
----

[](#手工安装)

推荐安装方式，通过编辑项目`composer.json`加入依赖`pinguo/php-msf`

```
{
    "require": {
        "pinguo/php-msf": ">=3.0.0"
    },
    "minimum-stability": "dev"
}
```

`"minimum-stability": "dev"`这个配置选项必须加上，因为日志组件依赖`"monolog/monolog": "2.0.x-dev"`，并且`monolog/monolog`无2.0的release包，不过我们在生产环境已经验证其稳定性。

项目原则
----

[](#项目原则)

### 稳定

[](#稳定)

php-msf经受了[Camera360](https://www.camera360.com)社区服务大流量、高并发的洗礼，稳定性得到充分验证。稳定性是我们花了大量时间、精力去解决的最重要问题，是三大原则的最重要原则。

### 高性能

[](#高性能)

IO密集性业务的单机处理能力提升5-10倍，这是生产环境中得出的真实数据，如Camera360社区某聚合服务在流量高峰需要40台服务器抗住流量，而采用php-msf重构之后只需要4台相同配置的服务器就可以抗住所有流量。

### 简单

[](#简单)

由于Swoole复杂的进程模型，并且有同步阻塞和异步非阻塞之分，所以在运行相同代码逻辑时，可能在调用方式、传递参数都不一致，从而直线拉高了学习成本，我们为了屏蔽低层的差异，做了大量的工作，实现和传统MVC框架的唯一区别在于添加“yield”关键字。我们参考了Yii2框架的部分代码实践，我们期望无缝的从Yii2开发切换过来。

上述三大原则，是我们在新增特性、功能实现时，投票或者合并代码的依据，任何影响这些原则的PR也将会被拒绝。

关于协程
----

[](#关于协程)

目前社区有几个PHP开源项目支持协程，它们大多采用Generator+Yield来实现，但是实现的细微差别会导致性能相差甚远，我们应该认识到协程能够以同步的代码书写方式而运行异步逻辑，故协程调度器的性能一定要足够的高，php-msf的协程调度性能是原生异步回调方式的80%，也就是说某个API采用原生异步回调写法QPS为10000，通过php-msf协程调度器调度QPS为8000。

为什么是微服务框架？
----------

[](#为什么是微服务框架)

目前php-msf还在起步阶段，我们花了大量的时间和精力解决稳定性、高性能、内存问题，因为我们认为“基石”是“万丈高楼”的最基本的保障，只有基础打得牢，才能将“大楼”建设得“更高”。3.0版本是我们开源的起始版本，是我们迈出的重要一步，接下来我们重点会是分布式微服务框架的打磨。

另外，由于基于PHP常驻进程，并直接解析HTTP或者TCP请求，这是服务化最重要的支撑，基于此我们可以做很多原来不敢去实现的想法，总之想像空间很大。

感谢
--

[](#感谢)

php-msf最开始基于[SwooleDistributed-1.7.x](https://github.com/tmtbe/SwooleDistributed/)开发，而此次开源版本中，连接池主要采用了SD的实现。由于我们框架定位、解决的业务场景、稳定性的要求、代码风格等差异太大，因此我们决定自主研发微服务框架，每个框架都有自己的特色和优点，选择合适自己公司和业务场景的框架最重要，同时在此也感谢[白猫](https://github.com/tmtbe)；另外，在研发php-msf框架及生产环境应用过程中，遇到很多底层问题，不过都一一解决，而这些问题能够解决最重要就是[Swoole](http://www.swoole.com)开源项目创始人[韩天峰-Rango](https://github.com/matyhtf)的大力支持，在此深表感谢。

License
-------

[](#license)

GNU General Public License, version 2 see

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community34

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 64.4% 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 ~46 days

Recently: every ~66 days

Total

7

Last Release

2893d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/73195cce221c441227e404e16ba55668266bcfec3b5b659c2cf344cdccb5ef53?d=identicon)[pinguo-zhanglu](/maintainers/pinguo-zhanglu)

---

Top Contributors

[![pinguo-xudianyang](https://avatars.githubusercontent.com/u/13619778?v=4)](https://github.com/pinguo-xudianyang "pinguo-xudianyang (683 commits)")[![xudianyang](https://avatars.githubusercontent.com/u/3177355?v=4)](https://github.com/xudianyang "xudianyang (204 commits)")[![pinguo-xiaoshiyong](https://avatars.githubusercontent.com/u/10018185?v=4)](https://github.com/pinguo-xiaoshiyong "pinguo-xiaoshiyong (128 commits)")[![shellvon](https://avatars.githubusercontent.com/u/3349696?v=4)](https://github.com/shellvon "shellvon (12 commits)")[![pinguo-zhanglu](https://avatars.githubusercontent.com/u/6878788?v=4)](https://github.com/pinguo-zhanglu "pinguo-zhanglu (11 commits)")[![sunny5156](https://avatars.githubusercontent.com/u/2882717?v=4)](https://github.com/sunny5156 "sunny5156 (6 commits)")[![viaweb3](https://avatars.githubusercontent.com/u/17975348?v=4)](https://github.com/viaweb3 "viaweb3 (4 commits)")[![syyongx](https://avatars.githubusercontent.com/u/7940171?v=4)](https://github.com/syyongx "syyongx (4 commits)")[![pinguo-lipengcheng](https://avatars.githubusercontent.com/u/26269071?v=4)](https://github.com/pinguo-lipengcheng "pinguo-lipengcheng (3 commits)")[![Kashin-J](https://avatars.githubusercontent.com/u/10087093?v=4)](https://github.com/Kashin-J "Kashin-J (1 commits)")[![toxmc](https://avatars.githubusercontent.com/u/3990846?v=4)](https://github.com/toxmc "toxmc (1 commits)")[![pinguo-zengzhiqiang](https://avatars.githubusercontent.com/u/30485345?v=4)](https://github.com/pinguo-zengzhiqiang "pinguo-zengzhiqiang (1 commits)")[![wiseker](https://avatars.githubusercontent.com/u/5337474?v=4)](https://github.com/wiseker "wiseker (1 commits)")[![pinguo-tonganping](https://avatars.githubusercontent.com/u/11658809?v=4)](https://github.com/pinguo-tonganping "pinguo-tonganping (1 commits)")

---

Tags

microservicemicroservice-frameworkmvcphpphp-frameworkphp-msfswooleswoole-framework

### Embed Badge

![Health badge](/badges/pinguo-php-msf/health.svg)

```
[![Health](https://phpackages.com/badges/pinguo-php-msf/health.svg)](https://phpackages.com/packages/pinguo-php-msf)
```

###  Alternatives

[projek-xyz/slim-plates

Render your Slim 3 application views using Plates template engine.

2678.2k3](/packages/projek-xyz-slim-plates)[forme/framework

An MVC framework for WordPress.

175.0k3](/packages/forme-framework)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

338.9k1](/packages/davidepastore-slim-config)

PHPackages © 2026

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