blob: 038045c8bb1cc91319a90c6ba0e3de6587d5183d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<?php
/**
* Class HTTPMockClient
*
* Does not really mock the client, it still does real connections but will retry failed connections
* to work around shaky connectivity.
*/
class HTTPMockClient extends HTTPClient {
protected $tries;
/**
* Sets shorter timeout
*/
function __construct() {
parent::__construct();
$this->timeout = 8; // slightly faster timeouts
}
/**
* Returns true if the connection timed out
*
* @return bool
*/
function noconnection() {
return ($this->tries === 0);
}
/**
* Retries sending the request multiple times
*
* @param string $url
* @param string $data
* @param string $method
* @return bool
*/
function sendRequest($url, $data = '', $method = 'GET') {
$this->tries = 2; // configures the number of retries
$return = false;
while($this->tries) {
$return = parent::sendRequest($url, $data, $method);
if($this->status != -100) break;
$this->tries--;
}
return $return;
}
}
|