From 0d493d4effb8994480976dee7042c498f2057df9 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Sun, 1 Dec 2013 15:12:54 +1300 Subject: [PATCH] FIX: allow CURLOPT_CONNECTTIMEOUT to be configured. --- api/RestfulService.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/api/RestfulService.php b/api/RestfulService.php index 76508a132..5f8d7ae29 100644 --- a/api/RestfulService.php +++ b/api/RestfulService.php @@ -1,17 +1,21 @@ Version(); $curlOptions = $curlOptions + (array)$this->config()->default_curl_options; @@ -221,7 +224,7 @@ class RestfulService extends ViewableData { curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $useragent); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->getConnectTimeout()); if(!ini_get('open_basedir')) curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); @@ -553,6 +556,31 @@ class RestfulService extends ViewableData { return $output; } + + /** + * Set the connection timeout for the curl request in seconds. + * + * @see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT + * + * @param int + * + * @return RestfulService + */ + public function setConnectTimeout($timeout) { + $this->connectTimeout = $timeout; + + return $this; + } + + /** + * Return the connection timeout value. + * + * @return int + */ + public function getConnectTimeout() { + return $this->connectTimeout; + } + } /**