我需要每秒运行 php 脚本,无论它运行多长时间。 尝试这样做:
#!/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()
但是 php 脚本的执行间隔不相等。比一秒钟多一点或少一点。提示如何正确地使间隔正好为一秒?不一定使用 python。
最佳答案
<?php
set_time_limit(60);
$start = time();
for ($i = 0; $i < 59; ++$i) {
// Do whatever you want here
time_sleep_until($start + $i + 1);
}
?>
关于php - 精确地每秒运行 php 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35829492/