Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
timer.php
1<?php
10
15class Timer
16{
18 protected $timeout;
19
21 protected $timeAtStart;
22
24 protected $limit;
25
27 protected $current = 0;
28
30 protected $isManualIncrement = false;
31
38 public function __construct($timeout = null, $limit = null)
39 {
40 $this->setLimit($limit)->setTimeout($timeout)->startTime();
41 }
42
48 public function isElapsed()
49 {
50 return ($this->isTimeout() || $this->isLimitExceeded());
51 }
52
58 public function enableManualIncrement()
59 {
60 $this->isManualIncrement = true;
61 return $this;
62 }
63
69 public function increment()
70 {
71 $this->current++;
72 return $this;
73 }
74
81 public function setLimit($limit)
82 {
83 $this->limit = $limit;
84 return $this;
85 }
86
93 public function setTimeout($timeout)
94 {
95 $this->timeout = $timeout;
96 return $this;
97 }
98
104 public function startTime()
105 {
106 if ($this->timeout)
107 {
108 $this->timeAtStart = getmicrotime();
109 @set_time_limit(0);
110 }
111
112 return $this;
113 }
114
120 public function isTimeout()
121 {
122 if (!$this->timeout)
123 {
124 return false;
125 }
126
127 return (getmicrotime() - $this->timeAtStart >= $this->timeout);
128 }
129
135 public function isLimitExceeded()
136 {
137 if (!$this->limit)
138 {
139 return false;
140 }
141
142 if (!$this->isManualIncrement)
143 {
144 $this->increment();
145 }
146
147 return ($this->current > $this->limit);
148 }
149}
__construct($timeout=null, $limit=null)
Definition timer.php:38