From 8b4180ca4a1770f4361f4b10992d034cefb4549c Mon Sep 17 00:00:00 2001 From: James Ebentier Date: Fri, 6 Feb 2015 11:16:16 -0800 Subject: [PATCH] PHP: moving over the addition of a setTimeout function for the APIClient --- .../src/main/resources/php/Swagger.mustache | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache index f8a602963b6..1aace837b1d 100644 --- a/modules/swagger-codegen/src/main/resources/php/Swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/php/Swagger.mustache @@ -37,6 +37,16 @@ class APIClient { $this->apiServer = $apiServer; } + /** + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + */ + public function setTimeout($seconds) { + if (!is_numeric($seconds)) { + throw new Exception('Timeout variable must be numeric.'); + } + $this->curl_timout = $seconds; + } + /** * @param string $resourcePath path to method endpoint @@ -72,7 +82,9 @@ class APIClient { $url = $this->apiServer . $resourcePath; $curl = curl_init(); - curl_setopt($curl, CURLOPT_TIMEOUT, 5); + if ($this->curl_timout) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timout); + } // return the result on success, rather than just TRUE curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);