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/utils:
use Http\Client\Utils\MessageFactory\GuzzleMessageFactory;
use Http\Client\Utils\StreamFactory\GuzzleStreamFactory;
use Http\Curl\CurlHttpClient;
$messageFactory = new GuzzleMessageFactory();
$client = new CurlHttpClient($messageFactory, new GuzzleStreamFactory());
$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);
use Http\Curl\CurlHttpClient;
use Mekras\HttplugDiactorosBridge\DiactorosMessageFactory;
use Mekras\HttplugDiactorosBridge\DiactorosStreamFactory;
$messageFactory = new DiactorosMessageFactory();
$client = new CurlHttpClient($messageFactory, new DiactorosStreamFactory());
$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);
You can use cURL options to configure CurlHttpClient:
use Http\Client\Utils\MessageFactory\GuzzleMessageFactory;
use Http\Client\Utils\StreamFactory\GuzzleStreamFactory;
use Http\Curl\CurlHttpClient;
$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);
These options can not ne used:
- CURLOPT_CUSTOMREQUEST
- CURLOPT_FOLLOWLOCATION
- CURLOPT_HEADER
- CURLOPT_HTTP_VERSION
- CURLOPT_HTTPHEADER
- CURLOPT_NOBODY
- CURLOPT_POSTFIELDS
- CURLOPT_RETURNTRANSFER
- CURLOPT_URL
These options can be overwritten by CurlHttpClient:
- CURLOPT_USERPWD
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 security@php-http.org.
The MIT License (MIT). Please see License File for more information.