How to create cron job using PHP?

前端 未结 12 1545
一整个雨季
一整个雨季 2020-11-21 05:50

I\'m new to using cron job. I don\'t even know how to write it. I have tried to search from internet, but I still don\'t understand it well. I want to create a cron job that

12条回答
  •  面向向阳花
    2020-11-21 06:02

    Better use the project Cron in combination with the Linux cronjob for this task. It allows you to configure run times in your PHP Code, support background jobs and is easy to use.

    First step call a PHP Script every minute:

    * * * * * /usr/local/bin/run.php &> /dev/null
    

    Second Step use the cron/cron Package to configure run times directly in PHP.

    $deprecatedStatus = new ShellJob();
    $deprecatedStatus->setCommand('cd /app && /usr/local/bin/php cron/updateDeprecatedStatus.php');
    $deprecatedStatus->setSchedule(new CrontabSchedule('* * * * */2'));
    
    
    $displayDate = new ShellJob();
    $displayDate->setCommand('cd /app && /usr/local/bin/php cron/updateDisplayDate.php');
    $displayDate->setSchedule(new CrontabSchedule('* * * * */5'));
    

    You found the details how to use in the linked repository.

提交回复
热议问题