Skip to content

Commit 9f87c4c

Browse files
committed
Merge pull request #81 from mekras/curl-client
Documentation for cURL client.
2 parents 5bc51b4 + bfaa0a4 commit 9f87c4c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

clients/curl-client.rst

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,69 @@
11
cURL Client
22
===========
3+
4+
This client uses `cURL PHP extension <http://php.net/curl>`_.
5+
6+
Installation
7+
------------
8+
9+
To install the cURL client, run:
10+
11+
.. code-block:: bash
12+
13+
$ composer require php-http/curl-client
14+
15+
Usage
16+
-----
17+
18+
The cURL client needs a :ref:`message <message-factory>` and a :ref:`stream <message-factory>`
19+
factory in order to to work::
20+
21+
use Http\Client\Curl\Client;
22+
23+
$client = new Client($messageFactory, $streamFactory);
24+
25+
Using `php-http/message <https://packagist.org/packages/php-http/message>`_::
26+
27+
use Http\Client\Curl\Client;
28+
use Http\Message\MessageFactory\DiactorosMessageFactory;
29+
use Http\Message\StreamFactory\DiactorosStreamFactory;
30+
31+
$client = new Client(new DiactorosMessageFactory(), new DiactorosStreamFactory());
32+
33+
Using `php-http/discovery <https://packagist.org/packages/php-http/discovery>`_::
34+
35+
use Http\Client\Curl\Client;
36+
use Http\Discovery\MessageFactoryDiscovery;
37+
use Http\Discovery\StreamFactoryDiscovery;
38+
39+
$client = new Client(MessageFactoryDiscovery::find(), StreamFactoryDiscovery::find());
40+
41+
Configuring client
42+
------------------
43+
44+
You can use `cURL options <http://php.net/curl_setopt>`_ to configure Client::
45+
46+
use Http\Client\Curl\Client;
47+
use Http\Discovery\MessageFactoryDiscovery;
48+
use Http\Discovery\StreamFactoryDiscovery;
49+
50+
$options = [
51+
CURLOPT_CONNECTTIMEOUT => 10, // The number of seconds to wait while trying to connect.
52+
CURLOPT_SSL_VERIFYPEER => false // Stop cURL from verifying the peer's certificate
53+
];
54+
$client = new Client(MessageFactoryDiscovery::find(), StreamFactoryDiscovery::find(), $options);
55+
56+
These options cannot be used (will be overwritten by Client):
57+
58+
* CURLOPT_CUSTOMREQUEST
59+
* CURLOPT_FOLLOWLOCATION
60+
* CURLOPT_HEADER
61+
* CURLOPT_HTTP_VERSION
62+
* CURLOPT_HTTPHEADER
63+
* CURLOPT_NOBODY
64+
* CURLOPT_POSTFIELDS
65+
* CURLOPT_RETURNTRANSFER
66+
* CURLOPT_URL
67+
* CURLOPT_USERPWD
68+
69+
.. include:: includes/further-reading-sync.inc

0 commit comments

Comments
 (0)