PHP sleep () inside the loop does not update the database

I have a php file that cronjob runs every minute.

When the php file is running, it updates the database, sleeps, etc.

It is programmed as follows:

$start = microtime(true);
set_time_limit(10);

for($i=0;$i<5;$i++)
{
    updateDB();
    time_sleep_until($start + $i + 1);
}

If this piece of code is running, I do not see any changes occurring in the database. Another thing that I notice is when I repeat something that I print, when the cycle ends in a whole.

[edit] I tried using flush and ob_flush, but it still did not print the line for the line [/ edit]

What can I do to avoid these errors. Database needs to be updated.

Another thing that I was curious about is the best way to register this. Can I write the results to a log file.

+3
2

. , updateDB().

-. . PHP , flush() , , ob_implicit_flush() script, , - .

, script , , .

, - - file_put_contents() , , FILE_APPEND .

+4

, , stderr, . $stderr = fopen ('php://stderr', 'w');

, . (fopen, fwrite, fclose);

0

Source: https://habr.com/ru/post/1723726/


All Articles