【问题标题】:job scheduling with at not working with php在不使用 php 的情况下安排工作
【发布时间】:2013-11-16 12:35:16
【问题描述】:

我正在尝试在 php 中执行 at 命令,但它不起作用..假设我想在 10 分钟后执行一个 php 脚本,所以我为它编写的代码..

ob_start();
system('echo curl http://www.domain.com/timetest.php | at now + 10 min 2>&1', $returnVal);
$output = ob_get_clean();

但是这个命令在控制台上运行良好,比如..

echo curl http://www.domain.com/timetest.php | at now + 10 min

如果我执行以下命令,它可以在控制台和 php 中工作,但它会立即执行脚本...

system('curl http://www.domain.com/timetest.php | at now + 10 min 2>&1', $returnVal);

我还通过谷歌搜索尝试了更多格式..like..

system('echo "curl http://www.domain.com/timetest.php" | at now + 10 min 2>&1', $returnVal);

请有人帮我把它弄好。 提前致谢。

【问题讨论】:

    标签: php command job-scheduling


    【解决方案1】:

    这将起作用:

    system('echo "curl http://...." | at now + 10 minutes', $retval);
    

    你也可以使用 bash 的 here-doc 语法:

    system('at now + 10 minutes <<EOF
        curl "http://..."
    EOF
    ', $retval);
    

    【讨论】:

    • 第一个我再次尝试但没有工作,第二个给出错误..“语法错误。看到的最后一个标记:c 乱码时间”
    • 如果你像这样尝试shell_exec() 会怎样:stackoverflow.com/questions/19980131/…
    • not working 是什么意思?你看我已经测试过了(以及另一个问题的开场白)
    • 不,只是文本,但换行符很重要。但是,第一种方法(echo)也应该起作用。你说它不起作用。这是什么意思?顺便说一句,您使用的是 Linux 还是 Windows?
    • 我正在使用 linux 服务器...当我使用 SSH 客户端运行此命令时... echo curl http://.... |现在 + 10 分钟,它工作正常
    猜你喜欢
    • 1970-01-01
    • 2011-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多