reactivex/rxphp
Composer 安装命令:
composer require reactivex/rxphp
包简介
Reactive extensions for php.
关键字:
README 文档
README
Reactive extensions for PHP. The reactive extensions for PHP are a set of libraries to compose asynchronous and event-based programs using observable streams.
Example
$source = \Rx\Observable::fromArray([1, 2, 3, 4]); $source->subscribe( function ($x) { echo 'Next: ', $x, PHP_EOL; }, function (Exception $ex) { echo 'Error: ', $ex->getMessage(), PHP_EOL; }, function () { echo 'Completed', PHP_EOL; } ); //Next: 1 //Next: 2 //Next: 3 //Next: 4 //Completed
Try out the demos
$ git clone https://github.com/ReactiveX/RxPHP.git
$ cd RxPHP
$ composer install
$ php demo/interval/interval.php
Have fun running the demos in /demo.
note: When running the demos, the scheduler is automatically bootstrapped. When using RxPHP within your own project, you'll need to set the default scheduler.
Installation
- Install an event loop. Any event loop should work, but the ReactPHP event loop is recommended.
$ composer require react/event-loop
- Install RxPHP using composer.
$ composer require reactivex/rxphp
- Write some code.
<?php require_once __DIR__ . '/vendor/autoload.php'; use Rx\Observable; use React\EventLoop\Factory; use Rx\Scheduler; $loop = Factory::create(); //You only need to set the default scheduler once Scheduler::setDefaultFactory(function() use($loop){ return new Scheduler\EventLoopScheduler($loop); }); Observable::interval(1000) ->take(5) ->flatMap(function ($i) { return Observable::of($i + 1); }) ->subscribe(function ($e) { echo $e, PHP_EOL; }); $loop->run();
Working with Promises
Some async PHP frameworks have yet to fully embrace the awesome power of observables. To help ease the transition, RxPHP has built in support for ReactPHP promises.
Mixing a promise into an observable stream:
Observable::interval(1000) ->flatMap(function ($i) { return Observable::fromPromise(\React\Promise\resolve(42 + $i)); }) ->subscribe(function ($v) { echo $v . PHP_EOL; });
Converting an Observable into a promise. (This is useful for libraries that use generators and coroutines):
$observable = Observable::interval(1000) ->take(10) ->toArray() ->map('json_encode'); $promise = $observable->toPromise();
Additional Information
License
RxPHP is licensed under the MIT License - see the LICENSE file for details
reactivex/rxphp 适用场景与选型建议
reactivex/rxphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.34M 次下载、GitHub Stars 达 1.73k, 最近一次更新时间为 2016 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extensions」 「reactive」 「rx」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 reactivex/rxphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reactivex/rxphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 reactivex/rxphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Websockets for PHP using Rx
A collection of functions to use with RxPHP
Async Reactive Postgres Driver for PHP (Non-blocking)
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
Register more Twig filters for your OctoberCMS templates
Bundle for Doctrine enumerations extension for Postgres
统计信息
- 总下载量: 3.34M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1735
- 点击次数: 21
- 依赖项目数: 61
- 推荐数: 12
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-23