1. Go to this page and download the library: Download stevad/yii-cron-tasks 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/ */
stevad / yii-cron-tasks example snippets
return array(
// import classes
'import' => array(
'ext.yii-cron-tasks.*'
),
'components' => array(
'cron' => array(
'class' => 'ext.yii-cron-tasks.CronService',
// next option must be a valid PHP callback, this is example
'tasksCallback' => array(
array('class' => 'application.models.AppCronTasks'),
'getList'
),
),
),
'commandMap' => array(
'cron' => array(
'class' => 'ext.yii-cron-tasks.CronCommand',
'enabled' => true // you can use this flag to quickly disable cron CLI commands if
class AppCronTasks
{
public function getList()
{
$tasks = array();
// call console command 'mail' with action 'sendInvites' every hour each 2 minutes starting from 9th
// and save output to protected/runtime/console-mail-invites.txt
$task1 = new CronTask('mail', 'sendInvites');
$tasks[] = $task1
->name('Send invites via mail')
->minute('9/2')
->setOutputFile(Yii::app()->getRuntimePath() . '/console-mail-invites.txt');
// call console command 'import' with action 'products' every day at 00:00 and save output
$task2 = new CronTask('import', 'products', array('removeOld' => 1));
$tasks[] = $task2
->name('Import products (daily)')
->daily()
->setOutputFile(Yii::app()->getRuntimePath() . '/product-import.txt');
return $tasks;
}
}
$task = new CronTask('command/action');
$task->daily()->hour(18);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.