Explorar o código

add net timeout

stanley-king %!s(int64=3) %!d(string=hai) anos
pai
achega
4995d24c91
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      core/framework/function/http.php

+ 6 - 0
core/framework/function/http.php

@@ -22,6 +22,8 @@ function http_request($url, $params = array(), $method = 'GET', $multi = false,
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ci, CURLOPT_HEADER, false);
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 60);
     curl_setopt($ci, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
 
     $headers = (array) $extheaders;
@@ -87,6 +89,8 @@ function http_post_data($url, $body, $headers = array(),&$net_errno = 0)
     curl_setopt($ci, CURLOPT_POSTFIELDS, $body);
     curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE);
     curl_setopt($ci, CURLOPT_URL, $url);
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 60);
     curl_setopt($ci, CURLOPT_POST, TRUE);
 
     if (!empty($headers)) {
@@ -116,6 +120,8 @@ function https_request($url, $params = array(), $method = 'GET', $multi = false,
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, 2);
+    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60);
+    curl_setopt($ci, CURLOPT_TIMEOUT, 60);
     curl_setopt($ci, CURLOPT_HEADER, false);
     $headers = (array) $extheaders;
     switch ($method)