K
K
karakazybra2017-03-13 13:08:33
PHP
karakazybra, 2017-03-13 13:08:33

How can I make the service add 1 word per page every minute?

Hi all. There is a completely blank page, how to make it add 1 random word from the list every minute? Service time from a week, with page cleaning after a certain number of words.
There is no cron on the hosting.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ildar Gizetdinov, 2017-03-13
@karakazybra

In this case, words with a period of 3 seconds

<?

$period = 3;

if (file_exists("last_time")) {
  $last_time = @file_get_contents("last_time");
  $current_time = time();
} else {
  $current_time = time();
  $last_time = $current_time-$period;
}

$steps = floor(($current_time - $last_time) / $period);

if ($steps > 0) {
  $words_list = array("слово 1", "слово 2", "слово 3", "слово 4", "слово 5", "слово 6", "слово 7", "слово 8");

  $words_add = array();
  for ($i = 0; $i < $steps; $i++) {
    $words_add[] = $words_list[rand(0, count($words_list)-1)];
  }
  
  $f = fopen("words", "a+");
  fwrite($f, implode("<br>", $words_add) . "<br>");
  fclose($f);

  file_put_contents("last_time", $current_time);
}

echo @file_get_contents("words");
?>

<script>
  setTimeout(function () {document.location.reload(); }, 3000);
</script>

E
Eugene, 2017-03-13
@GoldGoblin

refresh the page once per second. Use java script.

C
CityCat4, 2017-03-13
@CityCat4


There is no cron on the hosting.
There can be no cron on the hosting. Another thing is that there may not be access to its management :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question