phlib/jobqueue
Composer 安装命令:
composer require phlib/jobqueue
包简介
Job Queue implementation.
关键字:
README 文档
README
Job Queue implementation.
Install
Via Composer
$ composer require phlib/jobqueue
or
"require": { "phlib/jobqueue": "*" }
Basic Usage
Bootstrap
$beanstalk = (new \Phlib\Beanstalk\Factory())->create('localhost'); $db = new \Phlib\Db\Adapter(['host' => '127.0.0.1', 'dbname' => 'example']); $scheduler = new \Phlib\JobQueue\Scheduler\DbScheduler($db, 300, 600, true); $jobQueue = new \Phlib\JobQueue\Beanstalk\Scheduled($beanstalk, $scheduler);
Producer
$delay = strtotime('+1 week') - time(); $jobQueue->put('my-queue', ['my' => 'jobData'], ['delay' => $delay]);
Consumer
do { while ($job = $jobQueue->retrieve($queue)) { echo "Found new job {$job->getId()}\n", var_export($job->getBody(), true), "\n"; $jobQueue->markAsComplete($job); } usleep(500); } while (true);
See examples for more advance usage.
Jobqueue Script
The script has a dependency on two constructed objects. The Job Queue interface and the Scheduler interface. In order to provide this the following describes how they are injected into the script.
jobqueue-config.php (can be located in the root or config folder.
<?php $app = new MyApp(); return new \Phlib\JobQueue\Console\MonitorDependencies($app['jobqueue'], $app['scheduler']);
Table Schema
CREATE TABLE `scheduled_queue` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `tube` varchar(255) NOT NULL DEFAULT 'default', `data` blob NOT NULL, `scheduled_ts` timestamp NULL DEFAULT NULL, `priority` smallint(5) unsigned DEFAULT NULL, `ttr` smallint(5) unsigned DEFAULT NULL, `picked_by` varchar(20) DEFAULT NULL, `picked_ts` timestamp NULL DEFAULT NULL, `create_ts` timestamp NOT NULL, `update_ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `scheduled_ts` (`scheduled_ts`) ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4;
SQS Fair Queues
JobQueue can automatically set MessageGroupId from a parameter on the job's body see the AWS documentation for more information.
$client = new \Aws\Sqs\SqsClient(['region' => 'eu-west-1', 'credentials' => ['key' => 'foo', 'secret' => 'bar']]); $db = new \Phlib\Db\Adapter(['host' => '127.0.0.1', 'dbname' => 'example']); $scheduler = new \Phlib\JobQueue\Scheduler\DbScheduler($db, 300, 600, true); $jobQueue = new \Phlib\JobQueue\AwsSqs\JobQueue($client, $scheduler, '', 'tenantId'); //tenantId from the job body will be used as the MessageGroupId $job = new \Phlib\JobQueue\Job('my-queue', ['foo' => 'bar', 'tenantId' => 'tenant-26']); //MessageGroupId will get set to 'tenant-26' $jobQueue->put($job);
License
This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.
phlib/jobqueue 适用场景与选型建议
phlib/jobqueue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.28k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 03 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「task」 「beanstalk」 「job」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phlib/jobqueue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phlib/jobqueue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phlib/jobqueue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
$queue->push('I can be popped off after', '10 minutes');
PHP7.1+ client for beanstalkd work queue with no dependencies
PHP AMQP Binding Library
Library for handling beanstalk connections.
A Laravel package to monitor queue jobs.
含断线重连机制的Beanstalk PHP客户端。
统计信息
- 总下载量: 8.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2016-03-03