Skip to content

Commit 750ccf7

Browse files
authored
Merge pull request #211 from HongjiangHuang/chore/custome-apitimeout
feat: Custome api timeout support
2 parents 445cd22 + 7b7da13 commit 750ccf7

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/LeanCloud/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ public static function initialize($appId, $appKey, $appMasterKey) {
134134
Role::registerClass();
135135
}
136136

137+
/**
138+
* Set a deadline for requests to complete.
139+
*
140+
* Note that file upload requests are not affected.
141+
*
142+
* @param integer $seconds
143+
*/
144+
public static function setApiTimeout($seconds) {
145+
static::$apiTimeout = intval($seconds);
146+
}
147+
137148
/**
138149
* Assert client is correctly initialized
139150
*

test/APITest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,14 @@ public function testGzipCompatibility() {
226226
Client::delete("/classes/TestObject/{$resp['objectId']}");
227227
}
228228

229+
public function testRequestTimeout() {
230+
$getTimeout = function() { return static::$apiTimeout; };
231+
$getApiTimeout = $getTimeout->bindTo(null, Client::class);
232+
$this->assertEquals(15, $getApiTimeout());
233+
Client::setApiTimeout(3);
234+
$this->assertEquals(3, $getApiTimeout());
235+
Client::setApiTimeout(15); // revert to default
236+
}
237+
229238
}
230239

0 commit comments

Comments
 (0)