-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.php
50 lines (39 loc) · 1.72 KB
/
script.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
require_once('vendor/autoload.php');
use msb\model\Processing;
use msb\model\Schedule;
// Где будем хранить логи
$logFile = 'log/work.log';
// Проверяем, существует ли файл
if (!file_exists($logFile)) {
// Создаем файл
touch($logFile);
chmod($logFile, 0777);
}
// Устанавливаем максимальное время выполнения скрипта в 60 секунд
set_time_limit(60);
// Бесконечный цикл, который будет повторяться после завершения
while (true) {
// Checking the schedule, whether someone needs to send a message
(new Schedule())->check();
// Reply to all messages, once per second
$minute = gmdate("i");
$processing = new Processing();
while ($minute == gmdate("i")) {
echo PHP_EOL.gmdate("i:s");
$processing->check();
sleep(1);
}
// Let's create a mailing list for the day.
(new Schedule())->generate();
// Завершаем текущую итерацию, чтобы избежать нагрузки на сервер
sleep(1); // Задержка 1 секунда перед каждой итерацией цикла
// Определяем текущее время
$currentTime = time();
// Проверяем, если прошла минута, завершаем скрипт и перезапускаем его
if ($currentTime - $_SERVER['REQUEST_TIME'] >= 60) {
// Запускаем новый экземпляр скрипта
exec('php '.__FILE__.' >> /app/log/error.log 2>&1 &');
exit(); // Завершаем текущий экземпляр скрипта
}
}