bzrk / http-feeds-server
此项目是[HTTP Feeds](https://github.com/http-feeds/http-feeds)的PHP实现。
0.6
2022-02-13 15:34 UTC
Requires
- php: >=8
- ext-json: *
- bzrk/php-stream: ^0.10.0
- bzrk/php-timeunit: ^0.3.0
- psr/http-message: ^1.0
- psr/log: ^3.0
- ringcentral/psr7: ^1.3
- webmozart/assert: ^1.10
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- phpstan/phpstan: ^1.4
- phpunit/phpunit: ^9.5
README
此项目是[HTTP Feeds](https://github.com/http-feeds/http-feeds)的PHP实现。
HTTP Feeds
使用纯HTTP API进行异步事件流和数据复制的最小规范。
HTTP feeds是一个针对通过HTTP轮询事件的最低规范
- 一个HTTP feed提供了一个HTTP GET端点
- 它返回一系列按时间顺序排列的事件
- 以CloudEvents事件格式序列化
- 使用媒体类型
application/cloudevents-batch+json进行批量响应- 并尊重
lastEventId查询参数以滚动查看更多项目- 以支持无限轮询实时订阅。
HTTP feeds可用于解耦系统,无需消息代理异步进行,例如Kafka或RabbitMQ。
安装
composer require bzrk/http-feeds-server
与Slim一起使用
... class Repo implements Repository { public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection { .... } } $fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build(); $app = AppFactory::create(); $app->get('/', new HttpFeedsController($fetcher)); $app->addErrorMiddleware(true, true, true); $app->run();
与ReactPHP一起使用
... class Repo implements Repository { public function getByIdGreaterThan(string $lastEventId, int $limit): FeedItemCollection { .... } } $fetcher = HttpFeedsFetcher::builder(new Repo())->limit(10)->build(); $http = new React\Http\HttpServer(new HttpFeedsController($fetcher)); $socket = new React\Socket\SocketServer('0.0.0.0:8080'); $http->listen($socket);
参数
示例
轮询
http://server.com/inventory?lastEvenetId=1223
长轮询