diff --git a/README.md b/README.md index d7395ed..051ba0d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Event-driven, streaming HTTP client for [ReactPHP](http://reactphp.org) * [Basic usage](#basic-usage) * [Example](#example) +* [Advanced usage](#advanced-usage) + * [Unix domain sockets](#unix-domain-sockets) * [Install](#install) * [Tests](#tests) * [License](#license) @@ -98,6 +100,31 @@ $loop->run(); See also the [examples](examples). +## Advanced Usage + +### Unix domain sockets + +By default, this library supports transport over plaintext TCP/IP and secure +TLS connections for the `http://` and `https://` URI schemes respectively. +This library also supports Unix domain sockets (UDS) when explicitly configured. + +In order to use a UDS path, you have to explicitly configure the connector to +override the destination URI so that the hostname given in the request URI will +no longer be used to establish the connection: + +```php +$connector = new FixedUriConnector( + 'unix:///var/run/docker.sock', + new UnixConnector($loop) +); + +$client = new Client($loop, $connector); + +$request = $client->request('GET', 'http://localhost/info'); +``` + +See also [example #11](examples/11-unix-domain-sockets.php). + ## Install The recommended way to install this library is [through Composer](https://getcomposer.org). diff --git a/composer.json b/composer.json index c6c7b7e..e0bfba2 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.4.0", "guzzlehttp/psr7": "^1.0", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", - "react/socket": "^1.0 || ^0.8.3", + "react/socket": "^1.0 || ^0.8.4", "react/stream": "^1.0 || ^0.7.1", "react/promise": "~2.2", "evenement/evenement": "^3.0 || ^2.0" diff --git a/examples/11-unix-domain-sockets.php b/examples/11-unix-domain-sockets.php new file mode 100644 index 0000000..ecf22de --- /dev/null +++ b/examples/11-unix-domain-sockets.php @@ -0,0 +1,39 @@ +request('GET', 'http://localhost/info'); + +$request->on('response', function (Response $response) { + var_dump($response->getHeaders()); + + $response->on('data', function ($chunk) { + echo $chunk; + }); + + $response->on('end', function () { + echo 'DONE' . PHP_EOL; + }); +}); + +$request->on('error', function (\Exception $e) { + echo $e; +}); + +$request->end(); + +$loop->run();