Skip to content

Commit 1f11fa4

Browse files
committed
Merge pull request #72 from php-http/socket-client
Document Socket client
2 parents fa9580b + 1b1bbc6 commit 1f11fa4

File tree

6 files changed

+81
-6
lines changed

6 files changed

+81
-6
lines changed

Diff for: clients/guzzle6-adapter.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ Or send asynchronous ones::
4444
// Returns a Http\Promise\Promise
4545
$promise = $adapter->sendAsyncRequest(request);
4646

47-
Further reading
48-
---------------
49-
50-
* Read more about :doc:`promises </components/promise>`.
51-
* Learn how you can decouple your code from any PSR-7 implementation (such as
52-
Guzzle’s above) by using a :ref:`message factory <message-factory>`.
47+
.. include:: includes/further-reading-async.inc
5348

5449
.. _Guzzle 6 HTTP client: http://docs.guzzlephp.org/

Diff for: clients/includes/further-reading-async.inc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Further reading
2+
---------------
3+
4+
.. include:: includes/further-reading.inc
5+
6+
* Read more about :doc:`promises </components/promise>` when using asynchronous
7+
requests.

Diff for: clients/includes/further-reading-sync.inc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Further reading
2+
---------------
3+
4+
.. include:: includes/further-reading.inc

Diff for: clients/includes/further-reading.inc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* Use :ref:`plugins <plugins>` to customize the way HTTP requests are sent and
2+
responses processed by following redirects, adding Authentication or Cookie
3+
headers and more.
4+
* Learn how you can decouple your code from any PSR-7 implementation by using a
5+
:ref:`message factory <message-factory>`.

Diff for: clients/socket-client.rst

+62
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,64 @@
11
Socket Client
22
=============
3+
4+
The socket client uses the stream extension from PHP, which is integrated into
5+
the core.
6+
7+
Features
8+
--------
9+
10+
* TCP Socket Domain (``tcp://hostname:port``)
11+
* UNIX Socket Domain (``unix:///path/to/socket.sock``)
12+
* TLS / SSL encryption
13+
* Client Certificate (only for PHP > 5.6)
14+
15+
Installation
16+
------------
17+
18+
To install the Socket client, run:
19+
20+
.. code-block:: bash
21+
22+
$ composer require php-http/socket-client
23+
24+
Usage
25+
-----
26+
27+
The Socket client needs a :ref:`message factory <message-factory>` in order to
28+
to work::
29+
30+
use Http\Client\Socket\Client;
31+
32+
$options = [];
33+
$client = new Client($messageFactory, $options);
34+
35+
The available options are:
36+
37+
:remote_socket: Specify the remote socket where the library should send the request to
38+
39+
* Can be a TCP remote: ``tcp://hostname:port``
40+
* Can be a UNIX remote: ``unix:///path/to/remote.sock``
41+
* Do not use a TLS/SSL scheme, this is handle by the SSL option.
42+
* If not set, the client will try to determine it from the request URI or host header.
43+
:timeout: Timeout in milliseconds for writing request and reading response on the remote
44+
:ssl: Activate or deactivate SSL/TLS encryption
45+
:stream_context_options: Custom options for the context of the stream. See `PHP stream context options <http://php.net/manual/en/context.php>`_.
46+
:stream_context_params: Custom parameters for the context of the stream. See `PHP stream context parameters <http://php.net/manual/en/context.params.php>`_.
47+
:write_buffer_size: When sending the request we need to buffer the body, this option specify the size of this buffer, default is 8192,
48+
if you are sending big file with your client it may be interesting to have a bigger value in order to increase performance.
49+
50+
As an example someone may want to pass a client certificate when using the ssl, a valid configuration for this
51+
use case would be::
52+
53+
use Http\Client\Socket\Client;
54+
55+
$options = [
56+
'stream_context_options' => [
57+
'ssl' => [
58+
'local_cert' => '/path/to/my/client-certificate.pem'
59+
]
60+
]
61+
];
62+
$client = new Client($messageFactory, $options);
63+
64+
.. include:: includes/further-reading-sync.inc

Diff for: plugins/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _plugins:
2+
13
Plugins
24
=======
35

0 commit comments

Comments
 (0)