I want to execute php script at exact microtime, or after it if it hasn't been executed, 1minute is too much range for me. Is there such possibility?
Asked
Active
Viewed 53 times
-2
-
You should normally do fine with just one minute, why do you need it so exact? – HoogleyBoogley Sep 29 '17 at 20:24
-
2I'm not normal. – azurinko Sep 29 '17 at 20:27
-
Also I can push it down to one second. – azurinko Sep 29 '17 at 20:30
-
You can't do it to the exact second, as well as I don't think you would need it. If you have a chron job it would happen as soon as that minute hits, not anytime within that minute. – HoogleyBoogley Sep 29 '17 at 20:31
-
You can execute cron, and wait certain number of seconds... – azurinko Sep 29 '17 at 20:32
-
I still don't get the downvotes, are you angry that your langluage of choice doesnt handles? – azurinko Sep 29 '17 at 20:40
-
I think you should improve your question, add in what you have tried, what is the wrong result you're getting and how it should be if correct. A simple 'how should i do this?' Is too broad. – nl-x Sep 29 '17 at 21:23
-
I'm not even asking how should I do it, read the qustion. – azurinko Sep 29 '17 at 21:33
-
http://php.net/manual/en/function.usleep.php – azurinko Oct 05 '17 at 16:07
1 Answers
0
Assuming you already know how to use cron, set your script to start on the minute before the precise microtime you want stuff to happen. Pass the microtime value you want as an argument to the script and put this before the rest of your code.
<?php
// get the start time from the argument passed to the script
$startTime = $argv[1];
// wait until it's time
while (microtime(true) < $startTime);
// do stuff

Don't Panic
- 41,125
- 10
- 61
- 80