The cURL client use the cURL PHP extension which must be activated in your php.ini
.
Via Composer
$ composer require php-http/curl-client
Using php-http/discovery:
use Http\Client\HttpClient;
use Http\Curl\CurlHttpClient;
use Http\Discovery\MessageFactory\GuzzleMessageFactory;
use Http\Discovery\StreamFactory\GuzzleStreamFactory;
$messageFactory = new GuzzleMessageFactory();
$client = new CurlHttpClient($messageFactory, new GuzzleStreamFactory());
$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);
You can use cURL options to configure CurlHttpClient:
use Http\Client\HttpClient;
use Http\Curl\CurlHttpClient;
use Http\Discovery\MessageFactory\GuzzleMessageFactory;
use Http\Discovery\StreamFactory\GuzzleStreamFactory;
$options = [
CURLOPT_CONNECTTIMEOUT => 10, // The number of seconds to wait while trying to connect.
CURLOPT_SSL_VERIFYPEER => false // Stop cURL from verifying the peer's certificate
];
$client = new CurlHttpClient(new GuzzleMessageFactory(), new GuzzleStreamFactory(), $options);
Keep in mind that CurlHttpClient can overwrite some options like CURLOPT_RETURNTRANSFER
or
CURLOPT_FOLLOWLOCATION
.
Please see the official documentation.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please contact us at [email protected].
The MIT License (MIT). Please see License File for more information.