go to bug id or search bugs for
The connections my HttpRequest instances create appear to be getting reused in subsequent, entirely separate executions. This eventually causes my connections to hang on subsequent requests seemingly at random because the connection to the remote server has gone away due to idling but my end was never closed.
I have a script that just calls a fixed external endpoint using the HttpRequest class with a timeout of 30 seconds, nothing else. Most of the time it responds successfully (after around 600ms) but sometimes it throws a timeout. Monitoring network traffic shows the underlying connection getting reused from previous requests but the remote end never accepts the request, it has hung up from inactivity.
This functionality appears to be a way to achieve keep-alive connections within PHP. Adding the header "Connection: close" completely resolves this issue. Of course, this isn't a good solution.
Curl has the option "--keepalive-time", can that be set with HttpRequest? If so, how? If not, please allow that.
I *love* this library but this little surprise has caused me a lot of trouble.
Add a Patch
Add a Pull Request
Thanks for the report, I'll look into it!
There's actually no plan on adding features to pecl_http-v1.
TCP keepalive options are supported in v2, though: