PHP code example of anxu / crontab
1. Go to this page and download the library: Download anxu/crontab 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/ */
anxu / crontab example snippets
namespace app\commands;
use yii\console\Controller;
use anxu\Crontab\Crontab;
class DemoController extends Controller
{
public function actionIndex()
{
// 从数据库获取执行的任务
$jobs=[
[
'name'=>'1',
'schedule'=>'* * * * *',
'command'=>'date',
'output'=>'log/log.log'
],[
'name'=>'2',
'schedule'=>'* * * * *',
'command'=>'echo "test2"',
'output'=>'log/log.log'
]
];
$a = new Crontab();
$a->add($jobs);
$a->run();
}
}