16 return \Rsi\Record::get($this->_endpoints[$this->_endpointUrl],$key,$default);
20 if($this->_endpoint === null){
22 $this->_endpointUrl = $cache->_fetch($this->_endpointKey);
23 if(($this->_endpointUrl ===
false) || !array_key_exists($this->_endpointUrl,$this->_endpoints)){
25 foreach($this->_endpoints as $endpoint => $params)
26 $endpoints = array_merge($endpoints,array_fill(0,\
Rsi\Record::get($params,
'weight',1),$endpoint));
27 $this->_endpointUrl = $endpoints[rand(0,count($endpoints) - 1)];
28 $cache->_save($this->_endpointKey,$this->_endpointUrl,$this->
endpointParam(
'ttl',$this->_endpointTtl));
30 $this->
component(
'log')->debug(__CLASS__ .
"->endpointUrl = '{$this->_endpointUrl}'",__FILE__,__LINE__);
37 return $this->_endpoint ? $this->_endpoint->response :
false;
40 public function __call($func_name,$params){
42 $log->debug(__CLASS__ .
"::$func_name(...)",__FILE__,__LINE__);
43 while($this->_endpoints)
try{
44 return call_user_func_array([$this->endpoint,$func_name],$params);
47 $log->error(
'Endpoint error: ' . $e->getMessage(),__FILE__,__LINE__);
48 unset($this->_endpoints[$this->_endpointUrl]);
49 $this->_endpoint = null;
51 throw new Exception(
'No (more) endpoints');
endpointParam($key, $default=null)
$_endpointKey
Key for the last successful endpoint URL in the cache.
$_endpointTtl
Default TTL for the endpoint URL to be stored in the cache.
$_endpoints
Available endpoints (key = URL, value = params: username, password, timeout, ttl =.
component($name)
Get a component (local or default).
__call($func_name, $params)