cronos
如果您使用Symfony 4/5/6,则可以使用我们的Cool Bundle来通过Fancy注释来配置您的应用程序作业!
设置和配置
需要通过作曲家图书馆:
composer require mybuilder/ cronos
用法
建立cron
cronos\\Formatter\\Cron;
$cron
->header()
->setPath(\’path\’)
->setHome(\’home\’)
->setMailto(\’test@example.com\’)
->setShell(\’shell\’)
->setContentType(\’text\’)
->setContentTransferEncoding(\’utf8\’)
->end()
->comment(\’Comment\’)
->job(\’/bin/bash command –env=dev\’)
->setMinute(1)
->setHour(2)
->setDayOfMonth(3)
->setMonth(4)
->setDayOfWeek(5)
->setStandardOutFile(\’log\’)
->appendStandardErrorToFile(\’error\’)
->end();
echo $cron->format();\”>
<?php require \' vendor/autoload.php \' ; $ cron = new MyBuilder \\ cronos \\ Formatter \\ Cron ; $ cron -> header () -> setPath ( \' path \' ) -> setHome ( \' home \' ) -> setMailto ( \' test@example.com \' ) -> setShell ( \' shell \' ) -> setContentType ( \' text \' ) -> setContentTransferEncoding ( \' utf8 \' ) -> end () -> comment ( \' Comment \' ) -> job ( \' /bin/bash command --env=dev \' ) -> setMinute ( 1 ) -> setHour ( 2 ) -> setDayOfMonth ( 3 ) -> setMonth ( 4 ) -> setDayOfWeek ( 5 ) -> setStandardOutFile ( \' log \' ) -> appendStandardErrorToFile ( \' error \' ) -> end (); echo $ cron -> format ();
那将打印
MAILTO=test@example.com
HOME=home
SHELL=shell
LOGNAME=logName
CONTENT_TYPE=text
CONTENT_TRANSFER_ENCODING=utf8
#Comment
1 2 3 4 5 /bin/bash command --env=dev > log 2>> error
更新Cron
cronos\\Formatter\\Cron;
use MyBuilder\\ cronos \\Updater\\CronUpdater;
$cron = new Cron;
// $cron configuration…
$cronUpdater = CronUpdater::createDefault();
$cronUpdater->replaceWith($cron);\”>
<?php require \' vendor/autoload.php \' ; use MyBuilder \\ cronos \\ Formatter \\ Cron ; use MyBuilder \\ cronos \\ Updater \\ CronUpdater ; $ cron = new Cron ; // $cron configuration... $ cronUpdater = CronUpdater:: createDefault (); $ cronUpdater -> replaceWith ( $ cron );
故障排除
- 当前用户必须具有现有的crontab文件来使用更新器,使用
crontab -e创建一个。 - 执行CRON行时,它将与拥有Crontab的用户执行,但不会执行任何用户默认的Shell文件,因此需要在Cron Line调用的命令中指定所有路径等。
- 如果您在
/etc/passwd中没有可用的外壳,则不会执行您的crontab - 如果您的工作似乎没有运行,请检查Cron守护程序正在运行,还检查您的用户名在
/etc/cron.allow中,而不是在/etc/cron.deny中。 - 环境替代不起作用,您不能使用
$PATH,$HOME或~/sbin之类的东西。 - 您不能在命令中使用
%,如果您需要使用它,请在Backticks中逃脱命令。
由Mybuilder创建 – 查看我们的博客,以了解我们发布的此和其他开源项目。
