Adding Curl connect timeout configuration to PHP generation templates (#4500)

This commit is contained in:
Brian Voss 2017-01-06 03:14:39 -08:00 committed by wing328
parent aa1dc0fdd2
commit 43ab14b200
2 changed files with 39 additions and 0 deletions

View File

@ -153,6 +153,11 @@ class ApiClient
if ($this->config->getCurlTimeout() !== 0) { if ($this->config->getCurlTimeout() !== 0) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout());
} }
// set connect timeout, if needed
if ($this->config->getCurlConnectTimeout() != 0) {
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout());
}
// return the result on success, rather than just true // return the result on success, rather than just true
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

View File

@ -87,6 +87,13 @@ class Configuration
*/ */
protected $curlTimeout = 0; protected $curlTimeout = 0;
/**
* Timeout (second) of the HTTP connection, by default set to 0, no timeout
*
* @var string
*/
protected $curlConnectTimeout = 0;
/** /**
* User agent of the HTTP request, set to "PHP-Swagger" by default * User agent of the HTTP request, set to "PHP-Swagger" by default
* *
@ -370,6 +377,33 @@ class Configuration
return $this->curlTimeout; return $this->curlTimeout;
} }
/**
* Sets the HTTP connect timeout value
*
* @param integer $seconds Number of seconds before connection times out [set to 0 for no timeout]
*
* @return Configuration
*/
public function setCurlConnectTimeout($seconds)
{
if (!is_numeric($seconds) || $seconds < 0) {
throw new \InvalidArgumentException('Connect timeout value must be numeric and a non-negative number.');
}
$this->curlConnectTimeout = $seconds;
return $this;
}
/**
* Gets the HTTP connect timeout value
*
* @return string HTTP connect timeout value
*/
public function getCurlConnectTimeout()
{
return $this->curlConnectTimeout;
}
/** /**
* Sets debug flag * Sets debug flag
* *