@@ -11,6 +11,8 @@ Async HTTP CONNECT proxy connector, use any TCP/IP protocol through an HTTP prox
11
11
* [ ProxyConnector] ( #proxyconnector )
12
12
* [ Plain TCP connections] ( #plain-tcp-connections )
13
13
* [ Secure TLS connections] ( #secure-tls-connections )
14
+ * [ Connection timeout] ( #connection-timeout )
15
+ * [ DNS resolution] ( #dns-resolution )
14
16
* [ Advanced secure proxy connections] ( #advanced-secure-proxy-connections )
15
17
* [ Install] ( #install )
16
18
* [ Tests] ( #tests )
@@ -186,6 +188,85 @@ $connector->connect('tls://smtp.googlemail.com:465')->then(function (ConnectionI
186
188
> Also note how secure TLS connections are in fact entirely handled outside of
187
189
this HTTP CONNECT client implementation.
188
190
191
+ #### Connection timeout
192
+
193
+ By default, the ` ProxyConnector ` does not implement any timeouts for establishing remote
194
+ connections.
195
+ Your underlying operating system may impose limits on pending and/or idle TCP/IP
196
+ connections, anywhere in a range of a few minutes to several hours.
197
+
198
+ Many use cases require more control over the timeout and likely values much
199
+ smaller, usually in the range of a few seconds only.
200
+
201
+ You can use React's [ ` Connector ` ] ( https://github.com/reactphp/socket#connector )
202
+ or the low-level
203
+ [ ` TimeoutConnector ` ] ( https://github.com/reactphp/socket#timeoutconnector )
204
+ to decorate any given ` ConnectorInterface ` instance.
205
+ It provides the same ` connect() ` method, but will automatically reject the
206
+ underlying connection attempt if it takes too long:
207
+
208
+ ``` php
209
+ $connector = new Connector($loop, array(
210
+ 'tcp' => $proxy,
211
+ 'dns' => false,
212
+ 'timeout' => 3.0
213
+ ));
214
+
215
+ $connector->connect('tcp://google.com:80')->then(function ($stream) {
216
+ // connection succeeded within 3.0 seconds
217
+ });
218
+ ```
219
+
220
+ See also any of the [ examples] ( examples ) .
221
+
222
+ > Also note how connection timeout is in fact entirely handled outside of this
223
+ HTTP CONNECT client implementation.
224
+
225
+ #### DNS resolution
226
+
227
+ By default, the ` ProxyConnector ` does not perform any DNS resolution at all and simply
228
+ forwards any hostname you're trying to connect to the remote proxy server.
229
+ The remote proxy server is thus responsible for looking up any hostnames via DNS
230
+ (this default mode is thus called * remote DNS resolution* ).
231
+
232
+ As an alternative, you can also send the destination IP to the remote proxy
233
+ server.
234
+ In this mode you either have to stick to using IPs only (which is ofen unfeasable)
235
+ or perform any DNS lookups locally and only transmit the resolved destination IPs
236
+ (this mode is thus called * local DNS resolution* ).
237
+
238
+ The default * remote DNS resolution* is useful if your local ` ProxyConnector ` either can
239
+ not resolve target hostnames because it has no direct access to the internet or
240
+ if it should not resolve target hostnames because its outgoing DNS traffic might
241
+ be intercepted.
242
+
243
+ As noted above, the ` ProxyConnector ` defaults to using remote DNS resolution.
244
+ However, wrapping the ` ProxyConnector ` in React's
245
+ [ ` Connector ` ] ( https://github.com/reactphp/socket#connector ) actually
246
+ performs local DNS resolution unless explicitly defined otherwise.
247
+ Given that remote DNS resolution is assumed to be the preferred mode, all
248
+ other examples explicitly disable DNS resoltion like this:
249
+
250
+ ``` php
251
+ $connector = new Connector($loop, array(
252
+ 'tcp' => $proxy,
253
+ 'dns' => false
254
+ ));
255
+ ```
256
+
257
+ If you want to explicitly use * local DNS resolution* , you can use the following code:
258
+
259
+ ``` php
260
+ // set up Connector which uses Google's public DNS (8.8.8.8)
261
+ $connector = Connector($loop, array(
262
+ 'tcp' => $proxy,
263
+ 'dns' => '8.8.8.8'
264
+ ));
265
+ ```
266
+
267
+ > Also note how local DNS resolution is in fact entirely handled outside of this
268
+ HTTP CONNECT client implementation.
269
+
189
270
#### Advanced secure proxy connections
190
271
191
272
Note that communication between the client and the proxy is usually via an
0 commit comments