fubber/reactor
Composer 安装命令:
composer require fubber/reactor
包简介
An event based optionally forking PHP application server built on top of ReactPHP
README 文档
README
Fubber Reactor is an event driven and forking PHP application server based on the excellent ReactPHP event driven PHP framework. Fubber Reactor is an invitation to contribute in developing an awesome PHP application server that combines the best of PHP with the best of node.js.
Configuring Fubber Reactor
The simplest way to configure Fubber Reactor is via composer. Simply follow these steps:
-
Download and install composer (skip if you already have done this)
curl -sS https://getcomposer.org/installer | php -
Add Fubber Reactor as a dependency to your project
./composer.phar require fubber/reactor:dev-master -
Start Fubber Reactor
./vendor/bin/fubber-reactor
That's it! The default application should be serving at http://localhost:1337/. Check out the wiki for help on how to actually do some work!
Event Driven Controller and Forking Controller (beans)
With Fubber Reactor you'll configure URL-paths that map to instances of controller classes (beans). There are currently two types of controller classes:
Controller
The ordinary controller is used for page requests that should be run and handled within the standard ReactPHP event loop. The code running inside this controller should be non-blocking. This allows you to respond very quickly to page requests, and you'll also be able to maintain a client connection for a very long time, without incurring too much system overhead while doing so. Simply store a reference to the Response object in memory and whenever you want to write to it, just do so.
Forking Controller
The forking controller is special, in that it actually spawns off a fork of the main process. This allows you to perform non-blocking algorithms and requests, in a very similar manner to traditional PHP development. An average server can handle a few hundred running forking controllers, but the server will only allow a fork to run for up to 30 seconds. After 30 seconds, the server will dispatch a SIGHUP signal telling the controller to shut down. This will eventually be configurable.
Routing
Fubber Reactor has a special file based routing scheme. Every route is set up by creating an INI-file in the pages/ folder. The INI-files contains information about which class should be handling the request. In the current version, Fubber Reactor will instansiate an instance of the class for every URL you configure. Every request will then be sent to the Controller::listen($request, $response) method. That method will in turn call Controller::get($request, $response) for GET requests, Controller::post($request, $response) for POST requests and so on.
To create a route for a URL such as /users/12345/ you'll simply create an INI-file /pages/users/_/index.ini. This will cause an instance of your controller to get every request that maps to /pages/users/*/ according to the fnmatch() function.
Routing Algorithm:
- Exact matches are checked first. Exact matches will therefore be slightly faster. This means that if you create a file /pages/users/123/index.ini, this will be checked first.
- If no exact match is found, the router will scan the routing tables in order of number of wildcards in the route. A route with only one wildcard is checked before any route with two wildcards, and so on.
- If no routing matches are found, the request is rewritten to go to /errors/404. You should create a controller ini file at /pages/errors/404.ini to customize that error page. If no controller exists there, you will get a text based error page.
TODO
Fubber Reactor is a work in progress. I have a working and scalable publisher/subscriber server that will serve as an example application, and you can use that for sending push requests to your audience - for example to create a Twitter like experience, or something like a chat room.
These features are on my short-list:
- Implement Spring Framework style scopes. Currently only the Singleton scope is supported, although the Forking Controller resembles the Prototype scope due to forking.
- Create a Message Bus for the controllers to interact. This Message Bus must enable forking controllers to submit messages back to the application server and vice versa. Look into allowing this Message Bus to be cluster wide, for example by utilizing either the publisher/subscriber server written in Fubber Reactor itself, or by using an enterprise scale message queue.
- Create an Apache Simulator Controller, allowing developers to create ordinary PHP pages with access to the standard global objects such as $_COOKIE, $_SESSION, $_GET, $_POST etc. Should also handle file uploads. This will have to use the Forking Controller.
- Make a plugin architecture, for extending the functionality of Fubber Reactor. A suitable feature to add with this plugin architecture is a session handler. This plugin should be able to create Session Controller type.
- Create a special Cached Content Controller. The purpose of this controller is to enable pre-generated content to be served up.
fubber/reactor 适用场景与选型建议
fubber/reactor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「asynchronous」 「forking」 「application-server」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fubber/reactor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fubber/reactor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fubber/reactor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library to make setup and management of forking daemons in PHP easy.
Asynchronous coroutines for PHP 7.
Symfony ResqueBundle
Generic PHP Threads library using only pure PHP
Development and debugging tools for Recoil applications.
Async processing via process forking
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2015-02-02