@@ -122,6 +122,13 @@ class Api
122122 */
123123 private $ ms_between_retries ;
124124
125+ /**
126+ * The maximum time in seconds to wait for the response to arrive
127+ *
128+ * @var null|int
129+ */
130+ private $ timeout ;
131+
125132 /**
126133 * Create an L{API} object.
127134 *
@@ -147,6 +154,7 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/r
147154 $ this ->options = array ();
148155 $ this ->url_params = array ();
149156 $ this ->customHeaders = array ();
157+ $ this ->timeout = null ;
150158 }
151159
152160 /**
@@ -194,6 +202,15 @@ public function setMillisecondsBetweenRetries($ms_between_retries)
194202 {
195203 $ this ->ms_between_retries = $ ms_between_retries ;
196204 }
205+ /**
206+ * Sets the maximum time in seconds to wait for the response to arrive
207+ *
208+ * @param int $timeout
209+ */
210+ public function setTimeout ($ timeout )
211+ {
212+ $ this ->timeout = $ timeout ;
213+ }
197214
198215 /**
199216 * Returns response code.
@@ -469,7 +486,7 @@ private function callEndpoint($parameters, $subUrl)
469486 */
470487 private function makeRequest ($ url , $ headers , $ data , $ method )
471488 {
472- if ($ this ->request ->makeRequest ($ url , $ headers , $ data , $ method , $ this ->url_params ) === false ) {
489+ if ($ this ->request ->makeRequest ($ url , $ headers , $ data , $ method , $ this ->timeout , $ this -> url_params ) === false ) {
473490 throw new RosetteException ($ this ->request ->getResponseError ());
474491 } else {
475492 $ this ->setResponseCode ($ this ->request ->getResponseCode ());
0 commit comments