PHP code example of webman-tech / crontab-task

1. Go to this page and download the library: Download webman-tech/crontab-task 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/ */

    

webman-tech / crontab-task example snippets




namespace app\crontab\tasks;

use WebmanTech\CrontabTask\BaseTask;

class SampleTask extends BaseTask 
{
    /**
     * @inheritDoc
     */
    public function handle()
    {   
        // 实际业务
        echo date('Y-m-d H:i:s') . PHP_EOL;
    }
}



return (new Schedule())
    // 添加单个定时任务,独立进程
    ->addTask('task1', '*/1 * * * * *', \WebmanTech\CrontabTask\Tasks\SampleTask::class)
    // 添加多个定时任务,在同个进程中(注意会存在阻塞)
    ->addTasks('task2', [
        ['*/1 * * * * *', \WebmanTech\CrontabTask\Tasks\SampleTask::class],
        ['*/1 * * * * *', \WebmanTech\CrontabTask\Tasks\SampleTask::class],
    ])
    ->buildProcesses();