rundiz/php-scheduler

使用PHP在计划中运行任务。

1.0.2 2021-12-13 07:37 UTC

This package is auto-updated.

Last update: 2024-09-13 13:43:02 UTC


README

使用PHP在计划中运行任务。这不仅仅是cron作业或cron表,而是使用PHP的计划任务。
你可能不需要cron作业,如果没有cron作业,只需将其包含在当用户访问网页时总是被调用的主PHP文件中即可。

Latest Stable Version License Total Downloads

示例

$PhpSchedule = new \Rundiz\PhpSchedule\PhpSchedule();
$PhpSchedule->add('unique-name', 'https://mysite.localhost/page/to/works', ['12', '15']);// run on 12 (midday) and 15.
$PhpSchedule->run();

或者你可以使用你的函数/类来运行任务。

$PhpSchedule = new \Rundiz\PhpSchedule\PhpSchedule();
$PhpSchedule->add('unique-name1', 'myFunction', ['12', '15']);// run on 12 (midday) and 15.
$PhpSchedule->add('unique-name2', ['myStaticClass', 'myStaticMethod'], ['12', '15']);// run on 12 (midday) and 15.
$MyClass = new MyClass();
$PhpSchedule->add('unique-name3', [$MyClass, 'myMethod'], ['12', '15']);// run on 12 (midday) and 15.
$PhpSchedule->run();

更多示例,请查看 tests 文件夹。