Skip to content

Commit dc32f63

Browse files
committed
Document Socket client
1 parent 324d829 commit dc32f63

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

clients/socket-client.rst

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
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 need 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://hostname:port``
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+

0 commit comments

Comments
 (0)