21 protected function filename($func_name,$type,$period){
22 return $this->_path .
"/$func_name-$type-" . round(time() / $period) .
$this->_ext;
25 protected function inc($func_name,$type,$period){
26 file_put_contents($this->
filename($func_name,$type,$period),chr(65 + time() % 26),FILE_APPEND);
29 protected function count($func_name,$type,$period){
30 return \Rsi\File::size($this->
filename($func_name,$type,$period));
34 $period = max($this->countPeriod,$this->errorPeriod);
35 foreach($this->functions as $function) $period = max($period,$function[
'countPeriod'] ?? 0,$function[
'errorPeriod'] ?? 0);
37 \
Rsi\File::FIND_FILTER_NAME .
'-*' => $this->_ext,
38 \
Rsi\File::FIND_FILTER_TIME .
'<' => time() - $period
39 ]) as $filename => $info) \Rsi\File::unlink($filename);
42 public function __call($func_name,$params){
43 $config = $this->functions[$func_name] ?? [];
46 $callback = array_shift($params);
47 $result = $params ? array_shift($params) :
false;
51 ($this->
count($func_name,
'error',$error_period) > ($config[
'errorMax'] ?? $this->errorMax)) ||
53 ($count_max = $config[
'countMax'] ?? $this->countMax) &&
54 (($this->
count($func_name,
'start',$count_period) - $this->
count($func_name,
'stop',$count_period)) > $count_max)
58 if(!rand(0,$this->_garbageChance)) $this->
garbage();
60 $id = $log->start(
Log::DEBUG,$message =
"External call to '$func_name'",__FILE__,__LINE__,$config);
61 $this->
inc($func_name,
'start',$count_period);
62 $retry = $config[
'retryCount'] ?? 0;
64 $time = microtime(
true);
67 $result = call_user_func($callback);
68 $time = microtime(
true) - $time;
72 $time = microtime(
true) - $time;
73 $this->
inc($func_name,
'error',$error_period);
75 $error = $e->getMessage() .
' (' . $e->getFile() .
':' . $e->getLine() .
')';
76 if($retry > 0) usleep(($config[
'retryInterval'] ?? 100) * 1000);
78 $log->add($this->logPrio,$message,__FILE__,__LINE__,[
'funcName' => $func_name,
'time' => $time,
'error' => $error]);
82 $this->
inc($func_name,
'stop',$count_period);