@@ -64,6 +64,20 @@ final class ParseClient
64
64
*/
65
65
private static $ forceRevocableSession = false ;
66
66
67
+ /**
68
+ * Number of seconds to wait while trying to connect. Use 0 to wait indefinitely.
69
+ *
70
+ * @var int
71
+ */
72
+ private static $ connectionTimeout ;
73
+
74
+ /**
75
+ * Maximum number of seconds of request/response operation.
76
+ *
77
+ * @var int
78
+ */
79
+ private static $ timeout ;
80
+
67
81
/**
68
82
* Constant for version string to include with requests.
69
83
*
@@ -280,6 +294,14 @@ public static function _request($method, $relativeUrl, $sessionToken = null,
280
294
curl_setopt ($ rest , CURLOPT_CUSTOMREQUEST , $ method );
281
295
}
282
296
curl_setopt ($ rest , CURLOPT_HTTPHEADER , $ headers );
297
+
298
+ if (!is_null (self ::$ connectionTimeout )) {
299
+ curl_setopt ($ rest , CURLOPT_CONNECTTIMEOUT , self ::$ connectionTimeout );
300
+ }
301
+ if (!is_null (self ::$ timeout )) {
302
+ curl_setopt ($ rest , CURLOPT_TIMEOUT , self ::$ timeout );
303
+ }
304
+
283
305
$ response = curl_exec ($ rest );
284
306
$ status = curl_getinfo ($ rest , CURLINFO_HTTP_CODE );
285
307
$ contentType = curl_getinfo ($ rest , CURLINFO_CONTENT_TYPE );
@@ -439,4 +461,24 @@ public static function enableRevocableSessions()
439
461
{
440
462
self ::$ forceRevocableSession = true ;
441
463
}
464
+
465
+ /**
466
+ * Sets number of seconds to wait while trying to connect. Use 0 to wait indefinitely, null to default behaviour.
467
+ *
468
+ * @param int|null $connectionTimeout
469
+ */
470
+ public static function setConnectionTimeout ($ connectionTimeout )
471
+ {
472
+ self ::$ connectionTimeout = $ connectionTimeout ;
473
+ }
474
+
475
+ /**
476
+ * Sets maximum number of seconds of request/response operation. Use 0 to wait indefinitely, null to default behaviour.
477
+ *
478
+ * @param int|null $timeout
479
+ */
480
+ public static function setTimeout ($ timeout )
481
+ {
482
+ self ::$ timeout = $ timeout ;
483
+ }
442
484
}
0 commit comments