nyholm/psr7
Composer 安装命令:
composer require nyholm/psr7
包简介
A fast PHP7 implementation of PSR-7
README 文档
README
A super lightweight PSR-7 implementation. Very strict and very fast.
| Description | Guzzle | Laminas | Slim | Nyholm |
|---|---|---|---|---|
| Lines of code | 3.300 | 3.100 | 1.900 | 1.000 |
| PSR-7* | 66% | 100% | 75% | 100% |
| PSR-17 | No | Yes | Yes | Yes |
| HTTPlug | No | No | No | Yes |
| Performance (runs per second)** | 14.553 | 14.703 | 13.416 | 17.734 |
* Percent of completed tests in https://github.com/php-http/psr7-integration-tests
** Benchmark with 50.000 runs. See https://github.com/devanych/psr-http-benchmark (higher is better)
Installation
composer require nyholm/psr7
If you are using Symfony Flex then you get all message factories registered as services.
Usage
The PSR-7 objects do not contain any other public methods than those defined in the PSR-7 specification.
Create objects
Use the PSR-17 factory to create requests, streams, URIs etc.
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $request = $psr17Factory->createRequest('GET', 'http://tnyholm.se'); $stream = $psr17Factory->createStream('foobar');
Sending a request
With HTTPlug or any other PSR-18 (HTTP client) you may send requests like:
composer require kriswallsmith/buzz
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $psr18Client = new \Buzz\Client\Curl($psr17Factory); $request = $psr17Factory->createRequest('GET', 'http://tnyholm.se'); $response = $psr18Client->sendRequest($request);
Create server requests
The nyholm/psr7-server package can be used
to create server requests from PHP superglobals.
composer require nyholm/psr7-server
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $creator = new \Nyholm\Psr7Server\ServerRequestCreator( $psr17Factory, // ServerRequestFactory $psr17Factory, // UriFactory $psr17Factory, // UploadedFileFactory $psr17Factory // StreamFactory ); $serverRequest = $creator->fromGlobals();
Emitting a response
composer require laminas/laminas-httphandlerrunner
$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory(); $responseBody = $psr17Factory->createStream('Hello world'); $response = $psr17Factory->createResponse(200)->withBody($responseBody); (new \Laminas\HttpHandlerRunner\Emitter\SapiEmitter())->emit($response);
Our goal
This package is currently maintained by Tobias Nyholm and Martijn van der Ven. They have decided that the goal of this library should be to provide a super strict implementation of PSR-7 that is blazing fast.
The package will never include any extra features nor helper methods. All our classes and functions exist because they are required to fulfill the PSR-7 specification.
nyholm/psr7 适用场景与选型建议
nyholm/psr7 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 256.94M 次下载、GitHub Stars 达 1.27k, 最近一次更新时间为 2017 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「psr-7」 「psr-17」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nyholm/psr7 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nyholm/psr7 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nyholm/psr7 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Model of a web-based resource
Simple PHP Library for RESTful APIs
Multipart PSR-7 stream factories based on PSR-17 factories.
Interfaces for web resource models and services to retrieve and create them
PSR-7 (HttpMessage) & PSR-17 (HttpFactory) Implementations
Interface for a factory to create Psr\Http\Message\StreamInterface objects
统计信息
- 总下载量: 256.94M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1289
- 点击次数: 38
- 依赖项目数: 2718
- 推荐数: 190
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-12