dongnei3634 2018-08-02 05:21
浏览 125
已采纳

每10秒运行一次PHP脚本作为cron作业

This question may seem repetitive, as there are many threads around with the same subject, but thing is that most solutions seems to be linked with terminal coding, which i'm not comfortable with. The problem is simple i have a php script that needs to be executed very 10 seconds. Cron job in cpanel allows only upto 1 minute. What's the workaround to let cron work every 10 seconds ?

  • 写回答

4条回答 默认 最新

  • dqsong2010 2018-08-02 05:35
    关注

    Let the cron job run after every minute and in your php script the following code example might help you out. I have used counter limit to 6 because this script will run after every ten seconds and six times in one minute.

    <?php
    for($i=0;$i<6;$i++){
        sleep(10);
        task();
    }
    
    function task(){
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • doure5236 2018-08-02 05:26
    关注

    You can use simple bash-script like

    #!/bin/sh while [ true ] do php script.php sleep 10 done

    评论
  • dsdukbc60905239 2018-08-02 05:27
    关注

    CRON jobs are the standard way to run some tasks periodically. Setting cron jobs require access to the terminal. However, some shared hosting providers don't provide this and you need to set it up through their interface.

    If you hosting don't provide this you can third-party services that will call you url every 'X' seconds.

    Here are few of them:

    You can Google for more

    Note: You can have publically expose the PHP file as an url

    评论
  • dscc90150010 2018-08-02 05:32
    关注

    You can use the GUI Cpanel, select "once per minute" an try with something like the next command:

    /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php; sleep 10; /path/to/bin/php /path/to/script.php
    
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab runtime 如何收费
  • ¥20 用C语言绘制cs1.6方框透视 出现了点问题 绘制不上去 矩阵数据 和敌人坐标都是正确的
  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 生信simpleaffy包下载
  • ¥15 请教一下simulink中S函数相关问题
  • ¥15 在二层网络中,掩码存在包含关系即可通信
  • ¥15 端口转发器解析失败不知道电脑设置了啥
  • ¥15 Latex算法流程图行号自定义
  • ¥15 关于#python#的问题:我在自己的电脑上运行起来总是报错,希望能给我一个详细的教程,(开发工具-github)