Actually the question in the title. Task: Run the php script, but if all the conditions for its execution are not ready, then execute it again in 10 seconds? Is there any similar functionality in php?

  • one
    Historically, PCPs were not used for permanent work scripts, only on the principle “execution + completion”. With the advent of 7-pkhp in this plan it became much better. When I needed to organize such functionality, I did my implementation: I started the daemon and ran commands from the base. - Stanislav
  • @Stanislav yes, nothing has changed with the seven - etki

2 answers 2

Here is an example, a loop limited by three iterations ( $i < 3 ), which is executed with a delay of 10 seconds sleep(10) , if necessary, the number of iterations can be increased and / or you can add some condition instead of echo

 <?php for ($i=0; $i < 3; $i++) { $date = new DateTime(); echo "Итерация № $i, выполнена в " . $date->format("H:m:s") . "<br>"; sleep(10); } 
  • Very not bad, almost what I need. But the only problem is that when I use it on the page, for example, with this code, the page itself is loaded for 30 seconds ... - Bim Bam
  • one
    This is related to the output buffer on the screen, the information is not displayed immediately with each echo, but saved to the buffer and then all output (three iterations of 10 seconds last for exactly 30 seconds), at the php level this is solved by flushing () and flushing the buffer ob_flush (), but we must remember that at the level of the web server there is also a buffer, so this task should be solved on a specific configuration and this is a separate topic. For example, if you wake instead of echo to write a message in the file, there will be no 30 second delay and they will appear every 10 seconds. - 5f0f5
  • one
    Here you can read more about php buffer ru.stackoverflow.com/questions/554381/… - 5f0f5

For such purposes, you can use cron.