Skip to content

php-http/curl-client

Repository files navigation

Curl client for PHP HTTP

Latest Version Software License Build Status Code Coverage Quality Score Total Downloads

The cURL client use the cURL PHP extension which must be activated in your php.ini.

Install

Via Composer

$ composer require php-http/curl-client

Usage

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);

Configuring client

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

Documentation

Please see the official documentation.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please contact us at security@php-http.org.

License

The MIT License (MIT). Please see License File for more information.

About

cURL client

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 16

Languages