Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
timer.php
1<?php
2
4
9class Timer
10{
11 protected $finishTime;
12 protected $timeLimit;
13
18 public function __construct($newTimeLimit = 0, $increaseTimeLimit = true)
19 {
20 $startTime = (int)time();
21 $currentTimeLimit = ini_get('max_execution_time');
22
23 if($newTimeLimit > $currentTimeLimit || $newTimeLimit == 0)
24 $timeLimit = $newTimeLimit;
25 else
26 $timeLimit = $currentTimeLimit;
27
28 $this->timeLimit = $timeLimit;
29 if($increaseTimeLimit) {
30 $this->finishTime = $startTime + (int)($timeLimit);
31 @set_time_limit($timeLimit);
32 }
33 else {
34 $this->finishTime = $startTime + (int)($newTimeLimit);
35 }
36
37 }
38
44 public function check($reserveTime = 0)
45 {
46 if($this->timeLimit == 0)
47 return true;
48
49 if(time() < $this->finishTime - $reserveTime)
50 return true;
51
52 return false;
53 }
54}
__construct($newTimeLimit=0, $increaseTimeLimit=true)
Definition timer.php:18