time_interval.php 654 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/12/28
  6. * Time: 下午2:25
  7. */
  8. class time_interval
  9. {
  10. private $reset_time;
  11. private $interval;
  12. public function __construct($interval = 60) {
  13. $this->reset_time = 0;
  14. $this->interval = $interval;
  15. }
  16. public function need_init()
  17. {
  18. if($this->reset_time == 0) {
  19. $this->reset_time = time();
  20. return true;
  21. }
  22. else if((time() - $this->reset_time) < $this->interval) {
  23. return false;
  24. }
  25. else
  26. {
  27. $this->reset_time = time();
  28. return true;
  29. }
  30. }
  31. }