T
T
tajew2015-10-15 16:51:42
PHP
tajew, 2015-10-15 16:51:42

How to sort ad blocks by time?

Good afternoon.
There are n ad blocks on the page (from 3 to 20). The
task is to rotate these ad blocks, raising each of them up for a certain time.
Let's take for example 3 blocks
A
B
C
Within an hour, each of them should spend 20 minutes in the first place (60/3)
If there are 6 blocks, then 10 minutes each, respectively.
Tell me, how best to organize this?
Now I plan to run the script via cron every minute

$currentMinute = intval(date('i')); //Текущая минута
$count = 60/3; //Минуты делим на количество рекламных блоков, для примера взято 3
if($currentMinute%$count == 0) {
  //Код поднятия рекламного блока
}

Perhaps there is a better option?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksei Podgaev, 2015-10-15
@alexiusp

Is the page with blocks stored statically or pulled from the database?
If it's static, then yes, you can't do without cron. If in a DB it is also necessary to dance from it. If the page is generated dynamically, then the block sorting code must be run when the page is generated, and not on a schedule.
If the blocks should be swapped right in the user's browser, if, say, he keeps the page open for a long time (watching a movie from it or something), then client-side javascript needs to be used here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question