Reputation: 147
I need to run php script every second regardless of how long it will run. Tried to do it that way:
#!/usr/bin/python
import threading, time, os
def f():
os.system('php /var/www/test/artisan time:server > /dev/null &')
threading.Timer(1, f).start()
f()
but php script is executed with unequal intervals. A little more or a little less than one second. Prompt how correctly to make the intervals of exactly one second? Not necessarily with python.
Upvotes: 0
Views: 374
Reputation: 2713
<?php
set_time_limit(60);
$start = time();
for ($i = 0; $i <= 59; ++$i) {
// Do whatever you want here
time_sleep_until($start + $i + 1);
}
?>
Upvotes: 3
Reputation: 35337
The script finishing execution in exactly one second intervals, as in 1000000μs, is going to be nearly impossible to achieve just because of how processing works.
This would require:
You may be able to acheive one or two of these, but all three aren't realistic. Number 3 is going to be the main issue.
Upvotes: 1