amphp / websocket-client

Async WebSocket client for PHP based on Amp.

Home Page:https://amphp.org/websocket-client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Specify timeout

juzi5201314 opened this issue · comments

Allow specified connection timeout?
Now when the target cannot be accessed, "Uncaught Amp \ Socket \ ConnectException: Connecting to tcp: // localhost: 10000 failed: timeout exceeded (10000 ms)" will occur.
But the 10 second timeout is too long

The easiest way is to use a TimeoutCancellationToken passed to Connector::connect() to reduce the overall connection timeout.

You can also use the HttpClient passed to Rfc6455Connector to modify the request timeouts. However this is a bit clunky for something that should be simpler. In that light, I've added some methods to Handshake (in ab84d50) to easily modify the TCP connect timeout and TLS handshake timeout (if applicable).