version_checker.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 16/9/1
  6. * Time: 下午10:38
  7. */
  8. namespace activity;
  9. class version_checker
  10. {
  11. private $cur_version;
  12. private $reset_time;
  13. private $interval;
  14. public function __construct($keyword,$interval = 60)
  15. {
  16. $this->keyword = $keyword;
  17. $this->cur_version = 0;
  18. $this->reset_time = 0;
  19. $this->interval = $interval;
  20. }
  21. public function need_init()
  22. {
  23. if($this->reset_time == 0) {
  24. $this->reset_time = time();
  25. return true;
  26. }
  27. else if((time() - $this->reset_time) < $this->interval) {
  28. return false;
  29. }
  30. else
  31. {
  32. $need_reset = false;
  33. $version = rkcache($this->keyword);
  34. if(empty($version)) {
  35. $this->cur_version = 1;
  36. wkcache($this->keyword, $this->cur_version);
  37. $need_reset = true;
  38. $this->reset_time = time();
  39. }
  40. else
  41. {
  42. $version = intval($version);
  43. if($version > $this->cur_version) {
  44. $need_reset = true;
  45. $this->cur_version = $version;
  46. }
  47. $this->reset_time = time();
  48. }
  49. return $need_reset;
  50. }
  51. }
  52. }