It is necessary that every 12 hours from a certain time variable be increased by 1

I have a timer that at the end displays a message (a variable from a text file using php into an array), I want to do so that it is not necessary to constantly rewrite the string into a text document, and that at the end of the timer, a new variable is output each time (hence the other line from txt).

To do this, I want to make a php loop every 12 hours add variable 1 and the next element from the text document will be displayed.

  • 2
    write to the file the start time, calculate the difference and from it the current value of your variable. - vp_arth
  • I'm not a novice, but did not understand. Describe the task itself, not the cycles and timers - teran
  • if you have php, then somewhere you can probably put (or already is) a cron, make a small file and create a task to run the file every 12 hours. The file type will open the file, read the number, add 1, close the file. That's all - Vasily Barbashev

2 answers 2

Try to create for a start the right conditions for running, and then performing the script body itself. If you have it ready, then start with the cycle.

    This task is deterministic, it is not necessary to engage in its modeling in real time. You can calculate at any time what the counter value would be if you really performed all these operations.

    1. We determine the date / time of start
      $start = strtotime('2017-04-15 11:00:00');
    2. We get the current date / time
      $now = time();
    3. We calculate the value of our counter
      $i = floor(($now - $start) / (12*3600));

    Demo