From: Mikael Nordfeldth Date: Sun, 9 Jul 2017 18:07:18 +0000 (+0200) Subject: Configure a default timeout for HTTP connections at 60s X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f0480c34d7e3d528fc559568ce6ac53c3b33f8f9;p=quix0rs-gnu-social.git Configure a default timeout for HTTP connections at 60s No requests we do externally should ever take more than 60 seconds. This could probably be changed for downloading video or whatever for any cache plugins that want to store data locally, but in general I think even 60s is way longer than I expect any outgoing requests should take. This affects everything using HTTPClient, our helper class, and thus all hub pings, subscription requests, etc. etc. The value, afaik, includes connect_timeout and if it takes 10 seconds to establish a connection only 50 seconds is available to transfer data. --- diff --git a/lib/default.php b/lib/default.php index 90bca32c4f..b1079a907c 100644 --- a/lib/default.php +++ b/lib/default.php @@ -393,6 +393,7 @@ $default = 'ssl_verify_host' => true, // HTTPRequest2 makes sure this is set to CURLOPT_SSL_VERIFYHOST==2 if using curl 'curl' => false, // Use CURL backend for HTTP fetches if available. (If not, PHP's socket streams will be used.) 'connect_timeout' => 5, + 'timeout' => 60, 'proxy_host' => null, 'proxy_port' => null, 'proxy_user' => null, diff --git a/lib/httpclient.php b/lib/httpclient.php index 04a365274d..4891ff6440 100644 --- a/lib/httpclient.php +++ b/lib/httpclient.php @@ -116,6 +116,16 @@ class HTTPClient extends HTTP_Request2 function __construct($url=null, $method=self::METHOD_GET, $config=array()) { + if (is_int(common_config('http', 'timeout'))) { + // Reasonably you shouldn't set http/timeout to 0 because of + // malicious remote servers that can cause infinitely long + // responses... But the default in HTTP_Request2 is 0 for + // some reason and should probably be considered a valid value. + $this->config['timeout'] = common_config('http', 'timeout'); + common_debug('Using HTTPClient timeout value of '._ve($this->config['timeout'])); + } else { + common_log(LOG_ERR, 'config option http/timeout is not an integer value: '._ve(common_config('http', 'timeout'))); + } $this->config['connect_timeout'] = common_config('http', 'connect_timeout') ?: $this->config['connect_timeout']; $this->config['max_redirs'] = 10; $this->config['follow_redirects'] = true;