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