hzted123/yii2-cronjobs

Simple and convenient installing console commands as cron jobs for Yii framework

Installs: 3 943

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

1.0.1 2017-04-20 11:21 UTC

This package is not auto-updated.

Last update: 2024-04-17 17:41:08 UTC


README

Easiest way to put crontab on your console scripts.

This extension is based on this. Thanks Yiivgeny.

But with a few changes:

  • Work eith yii2
  • Set config in params (not in phpDocs).

Installation

  • Step 1: The preferred way to install this extension is through composer.

Either run

php composer.phar require hzted123/yii2-cronjobs "*"

or add

"hzted123/yii2-cronjobs": "*"

to the require section of your composer.json file.

  • Step 2: Set aliase @runnerScript in console config. This absolutely path to runner script Change path to runner script as your project.
Yii::setAlias('@runnerScript', dirname(__DIR__) . '/yii');
  • Step 3: Add to console config:
'controllerMap' => [
       'cron' => [
           'class' => 'hzted123\cronjobs\CronController',
           'cronJobs' =>[
        	'test/example1' => [
            		'cron'      => '* * * * *',            
        	],
		    'test/example2' => [
            		'cron'      => '10 * * * *',            
        	],

    	    ],
       ],
   ],
  • Step 4: Add task to system scheduler (cron on unix, task scheduler on windows) to run every minute:
* * * * * /path/to/yii/application/protected/yiic cron

You can point any settings from this.