Answer the question
In order to leave comments, you need to log in
How to perform an operation at a given exact time?
The point is this. There is a table in a DB with the schedule of certain actions. The time in the schedule is specified to the nearest second.
Task: perform tasks at the time specified in the schedule (error +/- 2 seconds is acceptable)
You can bypass the schedule using the crown no more than once a minute. But how, for example, to perform an action at 12:00:35 if cron runs the script at 12:00:00. Moreover, within one minute there can be more than one action, for example, at 12:00:20 and 12:00:50.
Answer the question
In order to leave comments, you need to log in
If such accuracy is needed, then only a demon.
upd: Perhaps an explanation is needed: You write a console script with an infinite loop that checks the database and compares the time of the event with the current one. If they match, then you do it. And you run this script in the php console /path/to/script/file.php
Let's say. Every minute, get tasks from the database for the next 60 seconds, sorted in ascending order. Loop through them each time checking the time difference, and set the required delay, then execute the task and repeat the process for the next one.
http://pro-pawn.ru/showthread.php?8215-Optimization...
But the problem is actually deeper. Let's say there are 50 events within a second. No matter how you create the timer, if it runs 1 script, then the 50th event will be executed after the 49th, and so on. And If this is php and there is no asynchrony of execution, then you can forget about the error of 2 seconds. Even if the timer works to within a tenth of a second.
Therefore, in my opinion, php is definitely not about it. As much as I love it, you probably need something else.
Or, as Lander wrote , launch a bunch of "demons", while the bunch should not be small and really work more often than the minimum required interval.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question