P
P
Pro100Sata2018-04-19 09:40:49
PHP
Pro100Sata, 2018-04-19 09:40:49

How can I make the counter reset at 00:00?

Hello everyone, please help with the counter... There is a counter that randomly adds to the number from 1 to 4...
The counter works fine, but how can I make it reset at 00:00 without cron?

The counter itself:

public function actionCounter(){
  
  $counter = 'counter/counter.txt';
  $all = file_exists($counter) ? (int) file_get_contents($counter) : 0;
  $rand_time = mt_rand(1, 4);
  $all = $all + $rand_time;
  $test = file_put_contents($counter, $all);
  $script_name = basename(__FILE__);
 
  return $all;
 
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2018-04-19
@saboteur_kiev

Save counter update time.
Count the difference between the current time and 00:00 today, compare with the time of the last update of the counter - if the update time was not today, reset it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question