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/message:
use Http\Client\Curl\Client;
use Http\Message\MessageFactory\DiactorosMessageFactory;
use Http\Message\StreamFactory\DiactorosStreamFactory;
$messageFactory = new DiactorosMessageFactory();
$client = new Client($messageFactory, new DiactorosStreamFactory());
$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);
Using php-http/discovery:
use Http\Client\Curl\Client;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\StreamFactoryDiscovery;
$messageFactory = MessageFactoryDiscovery::find();
$streamFactory = StreamFactoryDiscovery::find();
$client = new Client($messageFactory, $streamFactory);
$request = $messageFactory->createRequest('GET', 'http://example.com/');
$response = $client->sendRequest($request);
You can use cURL options to configure Client:
use Http\Client\Curl\Client;
use Http\Discovery\MessageFactoryDiscovery;
use Http\Discovery\StreamFactoryDiscovery;
$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 Client(MessageFactoryDiscovery::find(), StreamFactoryDiscovery::find(), $options);
These options can not be 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 Client:
- 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 [email protected].
The MIT License (MIT). Please see License File for more information.