1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * ChSpeed.php
- * stanley-king
- * 2024/3/28
- * PhpStorm
- * PHPProject
- */
- namespace refill;
- class chspeed
- {
- private $mChSpeedLimt = [];
- private $mChSpeedCur = [];
- public function __construct()
- {
- $this->load();
- }
- public function load()
- {
- $this->mChSpeedLimt = [];
- $all_ch_speeds = rkcachex('channel_speeds','refill-');
- if($all_ch_speeds === false) {
- return false;
- }
- $all_ch_speeds = json_decode($all_ch_speeds,true);
- if(empty($all_ch_speeds)) {
- return false;
- }
- foreach ($all_ch_speeds as $name => $speed) {
- $this->mChSpeedLimt[$name] = intval($speed);
- }
- }
- public function update_cur($speeds)
- {
- $this->mChSpeedCur = $speeds;
- }
- public function is_over_chspeed($chname)
- {
- $limit = $this->mChSpeedLimt[$chname] ?? -1;
- if ($limit <= 0) {
- return false;
- }
- $cur = $this->mChSpeedCur[$chname] ?? 0;
- return $cur >= $limit;
- }
- }
|