>本文介绍了Crunz,这是一个多功能的PHP作业计划库。 受Laravel的任务调度程序的启发,Crunz为管理Cron工作提供了增强的灵活性和易用性。 作者欢迎贡献和反馈。
>
>
密钥功能:
daily()
)。everyFiveMinutes()
>
from()
,to()
,between()
和when()
之类的方法,用于管理任务执行。skip()
>并行处理:同时执行任务以提高效率。>通过作曲家安装:
a
命令行实用程序将可用。<code class="language-bash">composer require lavary/crunz</code>>
crunz
它的工作方式:
>使用crunz接口,而不是直接在>文件中定义php文件中的cron作业(例如,在目录中)。 一个Cron Job(每分钟运行)将执行委派给Crunz的活动跑步者:
tasks/
>根据定义的时间表管理任务执行。crontab
>
<code class="language-bash">* * * * * /project/vendor/bin/crunz schedule:run</code>>任务文件创建:
schedule:run
)包含任务定义。 Crunz递归扫描目录。 您可以通过配置或命令行参数指定任务目录。>
>示例任务: Tasks.php
tasks/
>对象。
命令和闭合:<code class="language-php"><?php // tasks/MyTasks.php use Crunz\Schedule; $schedule = new Schedule(); $schedule->run('my_command') ->daily() ->description('My daily task.'); return $schedule;</code>
$schedule
接受命令或php封闭:
目录更改:
>使用在执行任务之前更改工作目录。run()
<code class="language-php">$schedule->run('/usr/bin/my_script.sh', ['--option' => 'value']) ->hourly(); $schedule->run(function () { /* code */ }) ->everyTenMinutes();</code>调度选项:
任务生命周期: , 有条件执行:和 > configuration(yaml):
hourly()
,daily()
,weekly()
,monthly()
,quarterly()
,yearly()
,everyFiveMinutes()
,everyTwelveHours()
等
on('14:00 2025-03-15')
,at('14:00')
。dailyAt('14:00')
mondays()
等(与其他频率方法一起使用)。tuesdays()
cron('30 12 * * 1')
from()
,to()
控制任务执行期。between()
when()
方法允许基于回调的有条件任务执行。skip()
crunz.yaml
>
crunz publish:config
symfony/Process
>preventOverlapping()
>输出和错误处理:
为单位)或通过电子邮件发送。 回调处理错误。
crunz.yaml
>onError()
pre/pre/后进程挂钩:
> 允许执行任务前后的代码。before()
>
after()
列表任务; 创建任务文件骨架。crunz schedule:list
crunz make:task
考虑使用(基于Laravel的接口)用于基于Web的管理解决方案。
lavary/crunz-ui
>在代码库中管理cron作业提供版本控制和更容易的协作。 crunz大大简化了这个过程。
>常见问题(常见问题解答):
(原始常见问题解答已经写得很好,不需要重大修改此重写。)>
以上是框架 - 敏捷的php php cronjobs用crunz变得容易了!的详细内容。更多信息请关注PHP中文网其他相关文章!