chspeed.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * ChSpeed.php
  4. * stanley-king
  5. * 2024/3/28
  6. * PhpStorm
  7. * PHPProject
  8. */
  9. namespace refill;
  10. class chspeed
  11. {
  12. private $mChSpeedLimt = [];
  13. private $mChSpeedCur = [];
  14. public function __construct()
  15. {
  16. $this->load();
  17. }
  18. public function load()
  19. {
  20. $this->mChSpeedLimt = [];
  21. $all_ch_speeds = rkcachex('channel_speeds','refill-');
  22. if($all_ch_speeds === false) {
  23. return false;
  24. }
  25. $all_ch_speeds = json_decode($all_ch_speeds,true);
  26. if(empty($all_ch_speeds)) {
  27. return false;
  28. }
  29. foreach ($all_ch_speeds as $name => $speed) {
  30. $this->mChSpeedLimt[$name] = intval($speed);
  31. }
  32. }
  33. public function update_cur($speeds)
  34. {
  35. $this->mChSpeedCur = $speeds;
  36. }
  37. public function is_over_chspeed($chname)
  38. {
  39. $limit = $this->mChSpeedLimt[$chname] ?? -1;
  40. if ($limit <= 0) {
  41. return false;
  42. }
  43. $cur = $this->mChSpeedCur[$chname] ?? 0;
  44. return $cur >= $limit;
  45. }
  46. }