每秒都从cron运行一个脚本

use*_*874 1 php cron crontab

我有一个脚本,我从浏览器运行元刷新,它在浏览器中没有任何问题,但它不会在cron中工作所以我可以做什么从cron运行每一秒?我知道睡眠我可以,但我必须在cron作业中创建几个cron选项卡,每次我必须运行脚本

有睡眠我怎么能每5秒运行一次这个脚本.

<meta http-equiv="refresh" content="5;url=test.php">
<?php
    $res = mysql_query("SELECT * FROM tableA where st='0' order by id asc LIMIT 1");
    $row = mysql_fetch_array($res);

    $link= $row['wl'];

    function getTitle($Url){
        $str = file_get_contents($Url);
        if(strlen($str)>0){
        preg_match("/\<\/td\><\/tr\><tr\><td colspan\=2\>(.*)\<\/td\>/",$str,$title);

            return $title[1];
        }
    }
    getTitle($link);
?>
Run Code Online (Sandbox Code Playgroud)

sec*_*tus 8

只需添加到您的crontab

* * * * * for i in {0..59}; do curl http://your.domain.zone/page.html && sleep 1; done;
Run Code Online (Sandbox Code Playgroud)

for 因为cron的运行速度不能超过每分钟一次.

  • 这将导致滞后:脚本的执行将花费一些时间,然后执行休眠1秒,依此类推; 在59次迭代之后,您会注意到总执行时间可能超过1分钟,导致脚本在近距离内执行两次. (2认同)