mekras / psr7-client
This package is abandoned and no longer maintained.
The author suggests using the php-http/curl-client package instead.
PSR-7 compatible HTTP client library
This package has no released version yet, and little information is available.
README
PSR-7 compatible HTTP client library.
Simple cURL based PSR-7 compatible HTTP client library.
Attention!
This package will be replaced with php-http/curl-client.
Migrating to Httplug
- Add php-http/httplug to your project requirements.
- Replace
Mekras\Http\Client\CurlHttpClient
andMekras\Interfaces\Http\Client\HttpClientInterface
withHttp\Client\HttpClient
in argument type hints - Replace send() method calls with sendRequest.
Mekras\Http\Client\CurlHttpClient
supports both Mekras\Interfaces\Http\Client\HttpClientInterface
and Http\Client\HttpClient
interfaces, so migration can be done gradually.
After dropping last Mekras\Interfaces\Http\Client\HttpClientInterface
usage:
- Add any of php-http/client-implementation to your project and configure it.
- Replace instances of
Mekras\Http\Client\CurlHttpClient
with instances of chosenphp-http/client-implementation
. - Remove
mekras/psr7-client
requirement from yourcomposer.json
.
Supported libraries
- guzzlehttp/psr7
- zendframework/zend-diactoros
- other by implementing ConnectorInterface
Usage
use GuzzleHttp\Psr7\Request; use Mekras\Http\Client\Connector\GuzzleConnector; use Mekras\Http\Client\CurlHttpClient; $client = new CurlHttpClient(new GuzzleConnector()); $request = new Request('GET', 'http://example.org/'); $response = $client->send($request); echo $response->getBody()->getContents());
Options
Options can be set via second argument in constructor. Available options are:
connection_timeout
(int) — connection timeout in seconds;curl_options
(array) — custom cURL options;decode_content
(bool) — see CURLOPT_ENCODING;follow_redirects
(bool) — automatically follow HTTP redirects;max_redirects
(int) — maximum nested redirects to follow;ssl_verify_peer
(bool) — verify peer when using SSLtimeout
(int) — overall timeout in seconds.use_cookies
(bool) — save and send cookies;
use Mekras\Http\Client\Connector\GuzzleConnector; use Mekras\Http\Client\CurlHttpClient; $client = new CurlHttpClient( new GuzzleConnector(), [ 'timeout' => 60, 'curl_options' => [ CURLOPT_CAPATH => '/path/to/ca' ] ] );