treffynnon/php-at-job-queue-wrapper

此包已被放弃,不再维护。未建议替代包。

Unix `at` 队列的 PHP 封装器

2.0.0 2020-07-10 09:51 UTC

This package is auto-updated.

Last update: 2022-07-18 23:59:48 UTC


README

build Latest Stable Version Total Downloads Latest Unstable Version License

一个封装 Unix/Linux `at/atd` 作业队列的 PHP 类。`at` 允许你在指定的时间点运行一个作业。有关 `at` 的更多信息,请在控制台运行 man at 或访问 手册页面。此类允许你将新项目添加到队列中,作为命令或文件的路径,并且还可以返回队列中已有的作业列表。你可以提供要使用的队列字母,这样你可以区分你的作业。例如:

迁移到 v2

由于 PHP 7.x 版本已经发布了一段时间,1.x 版本将不再活跃,请关注 2.x 版本。

require 'vendor/autoload.php';
use Treffynnon\At\Wrapper as At

// create a command job
$job = 'echo "hello" | wall';
$time = 'now + 1min';
// save command job to queue letter c
$queue = 'c';
At::cmd($job, $time, $queue);

// create a file job
$job = '/home/example/example.sh';
// save file job to queue letter f
$queue = 'f';
At::file($job, $time, $queue);

// create a file job and send it to
// the default queue (determined by at)
At::file($job, $time);

// get a list of all the jobs in the queue
var_dump(At::lq());

// get a list of all the jobs in the f queue
var_dump(At::lq('f'));

// get a list of all the jobs in the c queue
var_dump(At::listQueue('c'));

PHP 5.3 需要,以便支持命名空间的使用,但可以轻松移除以使其与 PHP 5.1 及以上版本向后兼容。

要求

  • Unix/Linux
  • at(你将已经安装了它,因为它包含在 Linux 发行版中)
  • 如果使用 PHP 5.3 及以上版本,由于代码中使用了命名空间,请使用 1.x 版本。
  • 如果使用 PHP 7.2+ 版本,请使用 2.x 版本。它将不支持 PHP 7.0 和 PHP 7.1 版本

安装

如果已在项目中设置/初始化 composer,您可以使用以下命令添加此项目:

composer require treffynnon/php-at-job-queue-wrapper

运行测试

克隆此存储库,并使用 composer 安装开发依赖项

composer install

完成后,您可以从 at 作业队列包装器的根目录中运行以下命令:

composer run-script test

from the root directory of the at Job Queue Wrapper.

解决失败的测试问题

如果您的 at 版本在添加新作业或列出 at 队列时输出不同,则测试可能会失败。该类在其属性中定义了长长的但简单的正则表达式。通过一点对正则表达式的了解,您可以修改这些表达式以适应您操作系统上的 at 二进制文件的输出。

如果您发现需要修改这些正则表达式,请向 github 报告问题。

当前测试输出样式

Redhat

添加作业

[root@server home]#  echo 'echo "hello" \| wall' | at now +10min
job 3 at 2010-11-15 10:54

列出队列

[root@server home]# at -l
2       2010-11-15 10:53 a root
3       2010-11-15 10:54 a root

Ubuntu

添加作业

user@server:~$ echo 'echo "hello" \| wall' | at now +10min
warning: commands will be executed using /bin/sh
job 17 at Mon Nov 15 10:55:00 2010

列出队列

user@server:~$ at -l
17      Mon Nov 15 10:55:00 2010 a simon
18      Mon Nov 15 10:55:00 2010 a simon