| Total Complexity | 10 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class IdleRecycling |
||
| 17 | { |
||
| 18 | use CWorker, ESJudger; |
||
|
|
|||
| 19 | |||
| 20 | /** |
||
| 21 | * @var Options |
||
| 22 | */ |
||
| 23 | private $options = null; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | private $idles = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * IdleRecycling constructor. |
||
| 32 | * @param Options $options |
||
| 33 | * @param Connections $connections |
||
| 34 | */ |
||
| 35 | public function __construct(Options $options, Connections $connections) |
||
| 36 | { |
||
| 37 | $this->options = $options; |
||
| 38 | |||
| 39 | $this->track($connections); |
||
| 40 | $this->ticker($options->icInterval, [$this, 'checking']); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param string $cid |
||
| 45 | */ |
||
| 46 | public function busying(string $cid) : void |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $cid |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | public function idling(string $cid) : bool |
||
| 56 | { |
||
| 57 | return ($last = $this->idles[$cid] ?? PHP_INT_MAX) ? time() - $last >= $this->options->idleTimeout : false; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | */ |
||
| 62 | public function checking() : void |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | */ |
||
| 75 | private function marking() : void |
||
| 79 | } |
||
| 80 | } |
||
| 82 |