PHP code example of wangruyi / php-crond

1. Go to this page and download the library: Download wangruyi/php-crond library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wangruyi / php-crond example snippets




use Wangruyi\PhpCrond\Scheduler;
use Wangruyi\PhpCrond\Job;

$sch = new Scheduler();

$job = new Job('* * * * *', 'php echo.php -a=1001', 'echo', 'log/echo.log');
$sch->addJob($job);

$job2 = new Job('*/2 * * * *', 'php -v', 'phpv', 'log/echo.log');
$sch->addJob($job2);

$sch->run();

public function __construct($moment, $command, $name='', $output='', $cwd=null)

$job = new Job('* * * * *', 'php echo.php', 'task', 'log/echo_{Ymd}.log');

$job->setOutput('log/another_{Ymd}.log');

namespace app\common\command\system;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use Wangruyi\PhpCrond\Job;
use Wangruyi\PhpCrond\Scheduler;

class Schedule extends Command
{
    protected function configure()
    {
        $this->setName('schedule:run')
            ->setDescription('定时任务调度器入口');
    }

    protected function execute(Input $input, Output $output)
    {
        $sch = new Scheduler();
        $jobs = [
            new Job('*/10 * * * *', 'php think order:stat', 'stat', '/var/logs/order_stat.log'),
            new Job('4 0 * * *', 'php think order:settlement', 'settlement', '/var/logs/order_settlement.log'),
        ];
        $sch->addJobs($jobs);
        $sch->run();
    }
}
bash
composer