mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-28 13:36:12 +02:00
Merge pull request #2699 from wilr/restfultimeout
FIX: allow CURLOPT_CONNECTTIMEOUT to be configured.
This commit is contained in:
commit
6ea59e68ad
@ -1,17 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* RestfulService class allows you to consume various RESTful APIs.
|
* RestfulService class allows you to consume various RESTful APIs.
|
||||||
|
*
|
||||||
* Through this you could connect and aggregate data of various web services.
|
* Through this you could connect and aggregate data of various web services.
|
||||||
* For more info visit wiki documentation - http://doc.silverstripe.org/doku.php?id=restfulservice
|
*
|
||||||
|
* @see http://doc.silverstripe.org/framework/en/reference/restfulservice
|
||||||
*
|
*
|
||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage integration
|
* @subpackage integration
|
||||||
*/
|
*/
|
||||||
class RestfulService extends ViewableData {
|
class RestfulService extends ViewableData {
|
||||||
|
|
||||||
protected $baseURL;
|
protected $baseURL;
|
||||||
protected $queryString;
|
protected $queryString;
|
||||||
protected $errorTag;
|
protected $errorTag;
|
||||||
protected $checkErrors;
|
protected $checkErrors;
|
||||||
|
protected $connectTimeout = 5;
|
||||||
protected $cache_expire;
|
protected $cache_expire;
|
||||||
protected $authUsername, $authPassword;
|
protected $authUsername, $authPassword;
|
||||||
protected $customHeaders = array();
|
protected $customHeaders = array();
|
||||||
@ -213,7 +217,6 @@ class RestfulService extends ViewableData {
|
|||||||
*/
|
*/
|
||||||
public function curlRequest($url, $method, $data = null, $headers = null, $curlOptions = array()) {
|
public function curlRequest($url, $method, $data = null, $headers = null, $curlOptions = array()) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
$timeout = 5;
|
|
||||||
$sapphireInfo = new SapphireInfo();
|
$sapphireInfo = new SapphireInfo();
|
||||||
$useragent = 'SilverStripe/' . $sapphireInfo->Version();
|
$useragent = 'SilverStripe/' . $sapphireInfo->Version();
|
||||||
$curlOptions = $curlOptions + (array)$this->config()->default_curl_options;
|
$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_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
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);
|
if(!ini_get('open_basedir')) curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
|
||||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||||
|
|
||||||
@ -553,6 +556,31 @@ class RestfulService extends ViewableData {
|
|||||||
|
|
||||||
return $output;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user