Download the PHP package yii2tech/crontab without Composer
On this page you can find all versions of the php package yii2tech/crontab. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package crontab
Crontab Extension for Yii 2
This extension adds Crontab setup support.
For license information check the LICENSE-file.
Requirements
This extension requires Linux OS. 'crontab' should be installed and cron daemon should be running.
Installation
The preferred way to install this extension is through composer.
Either run
or add
to the require section of your composer.json.
Usage
You can setup cron tab using [[yii2tech\crontab\CronTab]], for example:
You may specify particular cron job using [[yii2tech\crontab\CronJob]] instance, for example:
Tip: [[yii2tech\crontab\CronJob]] is a descendant of [[yii\base\Model]] and have built in validation rules for each parameter, thus it can be used in the web forms to create a cron setup interface.
Parsing cron jobs
[[yii2tech\crontab\CronJob]] composes a cron job line, like:
However it can also parse such lines filling up own internal attributes. For example:
Merging cron jobs
Method [[yii2tech\crontab\CronTab::apply()]] adds all specified cron jobs to crontab, keeping already exiting cron jobs intact. For example, if current crontab is following:
running following code:
will produce following crontab:
While merging crontab lines [[yii2tech\crontab\CronTab::apply()]] avoids duplication, so same cron job will never be added twice. However while doing this, lines are compared by exact match, inlcuding command and time pattern. If same command added twice with different time pattern - 2 crontab records will be present. For example, if current crontab is following:
running following code:
will produce following crontab:
You may interfere in merging process using [[yii2tech\crontab\CronTab::$mergeFilter]], which allows indicating
those existing cron jobs, which should be removed while merging. Its value could be a plain string - in this case
all lines, which contains this string as a substring will be removed, or a PHP callable of the following signature:
bool function (string $line)
- if function returns true
the line should be removed.
For example, if current crontab is following:
running following code:
will produce following crontab:
Extra lines setup
Crontab file may content additional lines beside jobs specifications. It may contain comments or extra shell configuration. For example:
You may append such extra lines into the crontab using [[yii2tech\crontab\CronTab::$headLines]]. For example:
Note: usage of the
headLines
may produce unexpected results, while merging crontab with existing one.
User setup
Each Linux system user has his own crontab. Ownership of crontab affected by this extension is determined by the user running the PHP script. For the web application it is usually 'apache', for the console application - current local user or root. Thus crontab application from web application and from console application will produce 2 separated cron jobs list for 2 different system users.
You may explicitly setup name of the user whose crontab is to be affected via [[yii2tech\crontab\CronTab::$username]]. For example:
However, this will work only in case PHP script is running from privileged user (e.g. 'root').