每秒从cron运行一个脚本 [英] running a script from cron every second

查看:168
本文介绍了每秒从cron运行一个脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have a script which i am running from browser with meta refresh and it workd without any issue in browser but it will not work in cron so what i can do to run every second from cron? i know with sleep i can but i have to create several cron tab in cron job and every time i have to run the script

睡眠我怎么可以运行此脚本每5秒。

with sleep how can i run this script every 5 sec.

<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);
?>


推荐答案

只需添加到crontab

Just add to your crontab

* * * * * for i in {0..59}; do curl http://your.domain.zone/page.html && sleep 1; done;

添加因为cron无法更快运行每分钟一次。

for added because cron could not run faster than once per minute.

这篇关于每秒从cron运行一个脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆