From 068395fcc12bca7c699d4040875086bdd05b0e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 17 Sep 2017 17:41:41 +0200 Subject: [PATCH] Update Socket dependency and support Unix Domain Sockets (UDS) again --- README.md | 26 ++++++++++++++++++++++++++ composer.json | 8 ++++---- examples/12-unix-domain-sockets.php | 27 +++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 examples/12-unix-domain-sockets.php diff --git a/README.md b/README.md index af136b9..a47b81e 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ mess with most of the low-level details. * [ResponseException](#responseexception) * [Advanced](#advanced) * [SOCKS proxy](#socks-proxy) + * [Unix domain sockets](#unix-domain-sockets) * [Options](#options) * [Install](#install) * [Tests](#tests) @@ -444,6 +445,31 @@ This works for both plain HTTP and SSL encrypted HTTPS requests. See also the [SOCKS example](examples/11-socks-proxy.php). +### 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 \React\Socket\FixedUriConnector( + 'unix:///var/run/docker.sock', + new \React\Socket\UnixConnector($loop) +); + +$browser = new Browser($loop, $connector); + +$client->get('http://localhost/info')->then(function (ResponseInterface $response) { + var_dump($response->getHeaders(), (string)$response->getBody()); +}); +``` + +See also the [Unix Domain Sockets (UDS) example](examples/12-unix-domain-sockets.php). + ### Options The [`Browser`](#browser) class exposes several options for the handling of diff --git a/composer.json b/composer.json index 1abb766..8d80377 100644 --- a/composer.json +++ b/composer.json @@ -17,16 +17,16 @@ "php": ">=5.4", "psr/http-message": "^1.0", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", - "react/http-client": "^0.5", + "react/http-client": "^0.5.6", "react/promise": "^2.2.1", "react/promise-stream": "^0.1.1", - "react/socket": "^1.0 || ^0.8", - "react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4.6", + "react/socket": "^1.0 || ^0.8.4", + "react/stream": "^1.0 || ^0.7", "ringcentral/psr7": "^1.2" }, "require-dev": { "clue/block-react": "^1.0", - "clue/socks-react": "^0.8 || ^0.7", + "clue/socks-react": "^0.8", "phpunit/phpunit": "^4.5", "react/http": "^0.7.2" } diff --git a/examples/12-unix-domain-sockets.php b/examples/12-unix-domain-sockets.php new file mode 100644 index 0000000..b42a445 --- /dev/null +++ b/examples/12-unix-domain-sockets.php @@ -0,0 +1,27 @@ +get('http://localhost/info')->then(function (ResponseInterface $response) { + echo Psr7\str($response); +}, 'printf'); + +$loop->run();