1. Go to this page and download the library: Download yzh52521/think-cron 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/ */
yzh52521 / think-cron example snippets
namespace app\task;
use yzh52521\cron\Task;
class DemoTask extends Task
{
public function configure()
{
$this->expression = "*/1 * * * *";
//设置任务的周期,每分钟执行一次,使用标准的Crontab语法,当配置文件中设置了执行周期将优先配置文件中的设置
}
/**
* 执行任务
* @return mixed
*/
protected function execute()
{
//...具体的任务执行
$time = date('Y-m-d H:i:s');
$this->statusDesc = $time;
return true;
}
}