PHP 클래스 yii2tech\crontab\CronTab

Note: Each system user has his own crontab, make sure you always run this class for the same user. For the web application it is usually 'apache', for the console application - current local user or root. Example usage: php 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();
또한 보기: CronJob
또한 보기: http://en.wikipedia.org/wiki/Crontab
부터: 1.0
저자: Paul Klimov ([email protected])
상속: extends yii\base\Component
파일 보기 프로젝트 열기: yii2tech/crontab 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$binPath path to the 'crontab' command, for example: '/usr/bin/crontab'. Default is 'crontab' assuming 'crontab' command is available in OS shell.
$defaultJobConfig default configuration for the cron job objects.
$headLines list of lines, which should be added at the beginning of the crontab. You can put comment lines and shell configuration here. For example: php [ '# crontab created by my application', 'SHELL=/bin/sh', 'PATH=/usr/bin:/usr/sbin', ]
$mergeFilter filter, which indicates whether existing cron job should be removed on cron tab merging. Value could be a plain string, which presence in the cron job line indicates it should be removed, or a callable of following signature: boolean function (string $line), which should return true, if line should be removed.

공개 메소드들

메소드 설명
apply ( ) : static Applies the current {@link jobs} to the current user crontab.
applyFile ( string $filename ) : static Setup the cron jobs from given file.
getCurrentLines ( ) : array Returns current cron jobs setup in the system for current user.
getJobs ( ) : array
getLines ( ) : array Returns the crontab lines composed from [[jobs]].
remove ( ) : static Removes current [[jobs]] from the current user crontab.
removeAll ( ) : static Removes all cron jobs for the current user.
saveToFile ( string $fileName ) : integer Saves the current jobs into the text file.
setJobs ( array $jobs ) : static

보호된 메소드들

메소드 설명
applyLines ( array $lines ) Applies given lines to current user crontab.
composeFileContent ( array $lines ) : string Composes the crontab file content from given lines.
composeJobLine ( yii2tech\crontab\CronJob | array $job ) : string Composes cron job line from configuration.
createJob ( array $config ) : yii2tech\crontab\CronJob Creates cron job instance from its array configuration.
mergeLines ( array $currentLines, array $newLines ) : array Merges existing crontab lines with new ones, applying [[mergeFilter]].

메소드 상세

apply() 공개 메소드

This method will merge new jobs with the ones already set in the system.
public apply ( ) : static
리턴 static self reference.

applyFile() 공개 메소드

Setup the cron jobs from given file.
public applyFile ( string $filename ) : static
$filename string file name.
리턴 static self reference.

applyLines() 보호된 메소드

Applies given lines to current user crontab.
protected applyLines ( array $lines )
$lines array crontab lines.

composeFileContent() 보호된 메소드

Composes the crontab file content from given lines.
protected composeFileContent ( array $lines ) : string
$lines array crontab lines.
리턴 string crontab file content.

composeJobLine() 보호된 메소드

Composes cron job line from configuration.
protected composeJobLine ( yii2tech\crontab\CronJob | array $job ) : string
$job yii2tech\crontab\CronJob | array cron job line or configuration.
리턴 string cron job line.

createJob() 보호된 메소드

Creates cron job instance from its array configuration.
protected createJob ( array $config ) : yii2tech\crontab\CronJob
$config array cron job configuration.
리턴 yii2tech\crontab\CronJob cron job instance.

getCurrentLines() 공개 메소드

Returns current cron jobs setup in the system for current user.
public getCurrentLines ( ) : array
리턴 array cron job lines.

getJobs() 공개 메소드

public getJobs ( ) : array
리턴 array

getLines() 공개 메소드

Returns the crontab lines composed from [[jobs]].
public getLines ( ) : array
리턴 array crontab lines.

mergeLines() 보호된 메소드

Merges existing crontab lines with new ones, applying [[mergeFilter]].
protected mergeLines ( array $currentLines, array $newLines ) : array
$currentLines array lines to be merged to
$newLines array lines to be merged from.
리턴 array merged lines

remove() 공개 메소드

Removes current [[jobs]] from the current user crontab.
public remove ( ) : static
리턴 static self reference.

removeAll() 공개 메소드

Removes all cron jobs for the current user.
public removeAll ( ) : static
리턴 static self reference.

saveToFile() 공개 메소드

Saves the current jobs into the text file.
public saveToFile ( string $fileName ) : integer
$fileName string output file name.
리턴 integer number of written bytes.

setJobs() 공개 메소드

public setJobs ( array $jobs ) : static
$jobs array
리턴 static self reference

프로퍼티 상세

$binPath 공개적으로 프로퍼티

path to the 'crontab' command, for example: '/usr/bin/crontab'. Default is 'crontab' assuming 'crontab' command is available in OS shell.
public $binPath

$defaultJobConfig 공개적으로 프로퍼티

default configuration for the cron job objects.
public $defaultJobConfig

$headLines 공개적으로 프로퍼티

list of lines, which should be added at the beginning of the crontab. You can put comment lines and shell configuration here. For example: php [ '# crontab created by my application', 'SHELL=/bin/sh', 'PATH=/usr/bin:/usr/sbin', ]
public $headLines

$mergeFilter 공개적으로 프로퍼티

filter, which indicates whether existing cron job should be removed on cron tab merging. Value could be a plain string, which presence in the cron job line indicates it should be removed, or a callable of following signature: boolean function (string $line), which should return true, if line should be removed.
public $mergeFilter