Demon has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58247


Change subject: Allow setting of connection timeouts for HTTP requests using 
cURL
......................................................................

Allow setting of connection timeouts for HTTP requests using cURL

Bug: 47027
Change-Id: I6e64a8bfc58e899149463d305eac672c1e8ad2ba
---
M includes/DefaultSettings.php
M includes/HttpFunctions.php
2 files changed, 16 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/47/58247/1

diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index d660f50..832f150 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6136,6 +6136,12 @@
  */
 $wgHTTPProxy = false;
 
+/**
+ * Timeout for connections done internally (in ms)
+ * Only works for curl
+ */
+$wgHTTPConnectTimeout = 500;
+
 /** @} */ # End HTTP client }
 
 /************************************************************************//**
diff --git a/includes/HttpFunctions.php b/includes/HttpFunctions.php
index acf9baa..40742af 100644
--- a/includes/HttpFunctions.php
+++ b/includes/HttpFunctions.php
@@ -40,6 +40,7 @@
         * @param array $options options to pass to MWHttpRequest object.
         *      Possible keys for the array:
         *    - timeout             Timeout length in seconds
+        *    - connectTimeout      Timeout for connection, in milliseconds 
(curl only)
         *    - postData            An array of key-value pairs or a 
url-encoded form data
         *    - proxy               The proxy to use.
         *                          Otherwise it will use $wgHTTPProxy (if set)
@@ -64,6 +65,9 @@
 
                if ( !isset( $options['timeout'] ) ) {
                        $options['timeout'] = 'default';
+               }
+               if( !isset( $options['connectTimeout'] ) ) {
+                       $options['connectTimeout'] = 'default';
                }
 
                $req = MWHttpRequest::factory( $url, $options );
@@ -231,6 +235,11 @@
                        $this->timeout = $options['timeout'];
                } else {
                        $this->timeout = $wgHTTPTimeout;
+               }
+               if ( isset( $options['connectTimeout'] ) && 
$options['connectTimeout'] != 'default' ) {
+                       $this->connectTimeout = $options['connectTimeout'];
+               } else {
+                       $this->connectTimeout = $wgHTTPConnectTimeout;
                }
                if( isset( $options['userAgent'] ) ) {
                        $this->setUserAgent( $options['userAgent'] );
@@ -721,6 +730,7 @@
 
                $this->curlOptions[CURLOPT_PROXY] = $this->proxy;
                $this->curlOptions[CURLOPT_TIMEOUT] = $this->timeout;
+               $this->curlOptions[CURLOPT_CONNECTTIMEOUT_MS] = 
$this->connectTimeout;
                $this->curlOptions[CURLOPT_HTTP_VERSION] = 
CURL_HTTP_VERSION_1_0;
                $this->curlOptions[CURLOPT_WRITEFUNCTION] = $this->callback;
                $this->curlOptions[CURLOPT_HEADERFUNCTION] = array( $this, 
"readHeader" );

-- 
To view, visit https://gerrit.wikimedia.org/r/58247
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6e64a8bfc58e899149463d305eac672c1e8ad2ba
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Demon <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to