首页 > 解决方案 > 如何在 Dreamhost 中使用 php 设置 cron?

问题描述

我想知道如何让这个 cron 工作在 Dreamhost 服务器中工作:

    $cron = '15 * * * * /usr/local/php71/bin/php '. ' /home/username/run.php >> /home/username/cron.out';

    try{

    $output = shell_exec('crontab -l');
    $job = '';
    $cronfile = '/home/username/tmp/crontab.txt';

    file_put_contents($cronfile, " ");   
    $job = $output . ' ' . $cron;
    file_put_contents($cronfile, $job . PHP_EOL, FILE_APPEND);    
    echo exec('crontab ' . $cronfile);
    echo 'Successful cron job task';
    }catch(Exception $ex){
        error_log("Errors while setting up cron $ex");
    }   

这是 run.php 中的内容:

<?php
error_log("Called from cron job");
?>

但我没有看到来自 run.php 的任何日志。我应该怎么做才能正确配置并成功完成 cron 作业?

标签: phpcron

解决方案


推荐阅读