php - 精确地每秒运行 php 脚本?

标签 php linux

我需要每秒运行 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/

相关文章:

php - jquery 与 PHP mySQL 聊天

php - 由于 CORS,Azure 网站上的 HTTP OPTIONS 请求失败

php - 从列中选择唯一值

php - Git POST webhook shell_exec

c - 有没有合适的方法来编写连续运行的程序

php - zend 框架 : "A project profile was not found" zf version 1. 11.7

php - Symfony 2.3.5 从文件创建数据库模式失败

linux - 编译 libsndfile,没有找到 FLAC

linux - 查找文件并重定向屏幕上找到的第一个文件的内容

linux - 计算linux中处理器核心数