G
G
grenline1231232021-06-13 17:26:07
PHP
grenline123123, 2021-06-13 17:26:07

A timer that doesn't stop the script?

I need to make an infinite timer, but when the script is run, it just loops and does not allow the rest of the code to work, it is impossible to get a variable using ajax, how can I implement the timer differently?

# Таймер
while(1) {
    if($pump > 200) continue; // Условие не пропускает дальше код если насос не работает
    if(date("H:i:s") == '23:59:59') { // Проверка времени если время 00:00 запись в базу данных и обнуляем таймер

        # Переводим секунды в минуты
        $time = date("i", mktime(0, 0, $time)); 

        # Получаем текущую дату
        $date = date('Y.m.d H:i:s');

        # Запрос в базу данных на добавление новой записи
        $sql = "INSERT INTO 
        `timeupdate` (`time`, `date`) VALUES '{$time}', {$date}";
        $dbh->query($sql);
    }
    $time++;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2021-06-14
@Nc_Soft

You're trying to invent monitoring. Look at prometheus or zabbix

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question