PHP code example of yii2tech / crontab

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

    

yii2tech / crontab example snippets


use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->setJobs([
    [
        'min' => '0',
        'hour' => '0',
        'command' => 'php /path/to/project/yii some-cron',
    ],
    [
        'line' => '0 0 * * * php /path/to/project/yii another-cron'
    ]
]);
$cronTab->apply();

use yii2tech\crontab\CronJob;
use yii2tech\crontab\CronTab;

$cronJob = new CronJob();
$cronJob->min = '0';
$cronJob->hour = '0';
$cronJob->command = 'php /path/to/project/yii some-cron';

$cronTab = new CronTab();
$cronTab->setJobs([
    $cronJob
]);
$cronTab->apply();

use yii2tech\crontab\CronJob;

$cronJob = new CronJob();
$cronJob->setLine('0 0 * * * php /path/to/my/project/yii some-cron');

echo $cronJob->min; // outputs: '0'
echo $cronJob->hour; // outputs: '0'
echo $cronJob->day; // outputs: '*'
echo $cronJob->month; // outputs: '*'
echo $cronJob->command; // outputs: 'php /path/to/my/project/yii some-cron'

use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->setJobs([
    [
        'min' => '0',
        'hour' => '0',
        'weekDay' => '5',
        'command' => 'php /path/to/project/yii weekly-cron',
    ],
]);
$cronTab->apply();

use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->setJobs([
    [
        'min' => '15',
        'hour' => '2',
        'command' => 'php /path/to/project/yii some-cron',
    ],
]);
$cronTab->apply();

use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->mergeFilter = '/path/to/project/yii'; // filter all invocation of Yii console
$cronTab->setJobs([
    [
        'min' => '15',
        'hour' => '2',
        'command' => 'php /path/to/project/yii some-cron',
    ],
]);
$cronTab->apply();

use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->headLines = [
    '# this crontab created by my application',
    'SHELL=/bin/sh',
    'PATH=/usr/bin:/usr/sbin',
];
$cronTab->setJobs([
    [
        'min' => '0',
        'hour' => '0',
        'command' => 'php /path/to/project/yii some-cron',
    ],
]);
$cronTab->apply();

use yii2tech\crontab\CronTab;

$cronTab = new CronTab();
$cronTab->username = 'www-data'; // apply crontab for 'www-data' user
$cronTab->setJobs([
    [
        'min' => '0',
        'hour' => '0',
        'command' => 'php /path/to/project/yii some-cron',
    ],
]);
$cronTab->apply();

php composer.phar