semperton / proxy
简单的PHP代理
0.2.1
2021-06-12 10:11 UTC
Requires
- php: >=7.1
- psr/http-client: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- httpsoft/http-message: ^1.0
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^4.7
README
Semperton Proxy
基于PHP原生流套接字的简单PSR-18 HTTP客户端。
安装
仅使用Composer
composer require semperton/proxy
代理需要PHP 7.1+
使用方法
客户端本身不带PSR-17请求/响应工厂。您必须在构造函数中提供它。
use HttpSoft\Message\ResponseFactory; use Semperton\Proxy\Client; $client new Client( new ResponseFactory(), // any PSR-17 compilant response factory 5, // request timeout in secs $options, // array of stream context options 4096 // buffer size used to read/write request body );
客户端仅暴露一个公共方法 sendRequest
use HttpSoft\Message\RequestFactory; use Psr\Http\Message\ResponseInterface; $requestFactory = new RequestFactory(); $request = $requestFactory->createRequest('GET', 'https://google.com'); $response = $client->sendRequest($request); $response instanceof ResponseInterface // true
注意
这是一个仅为单个请求设计的非常简单的HTTP客户端。如果您要进行大量的API工作(多个异步请求、体解析等),应考虑使用 guzzlehttp/guzzle
或 symfony/http-client
。