sebastianfeldmann / crontab
使用一些简单的PHP命令来管理您的crontab。
dev-master / 1.0.x-dev
2020-05-01 13:12 UTC
Requires
- php: >=7.1.0
- ext-spl: *
- sebastianfeldmann/cli: ~1.0
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-08-29 04:25:34 UTC
README
功能
使用优雅的OO接口列出所有cron作业。将作业添加到您的crontab。
要求
- PHP >= 7.0
- 带有crontab命令的POSIX Shell
安装
通过Composer安装crontab。
"require": { "sebastianfeldmann/crontab": "~1.0" }
使用方法
读取crontab
$crontab = new SebastianFeldmann\Crontab\Operator(); foreach ($crontab->getJobs() as $job) { echo "Description: . PHP_EOL . implode(PHP_EOL, $job->getComments()) . PHP_EOL; echo "Schedule: " . PHP_EOL . $job->getSchedule() . PHP_EOL; echo "Command: " . PHP_EOL . $job->getCommand() . PHP_EOL; }
将作业添加到crontab
$crontab = new SebastianFeldmann\Crontab\Operator(); $crontab->addJob( new SebastianFeldmann\Crontab\Job( '30 4 * * *', '/foo/bar/binary', ['Some foo bar binary execution'] ) );
这将把以下行添加到您的crontab中。
# Some foobar binary execution
30 4 * * * /foo/bar/binary
crontab解析器正在查找命令及其描述在上面的命令行中。解析器期望命令不要通过反斜杠(\)分布在多行上。
# Descriptoon for some command
10 23 * * * some command
# Next Command Description
# even more description for the next command
30 5 * * * next command