tomahawk/queue
Composer 安装命令:
composer require tomahawk/queue
包简介
Tomahawk Queue
README 文档
README
A nice and simple PHP Worker Queue library
Requirements
- PHP 7.0 +
- pcntl extension.
- posix extension.
Installation
You can install Tomahawk Queue using composer:
composer require tomahawk/queue
1. Setup configuration
First you need to create a new file called tomahawk.xml
You will need to configure the following things:
- Storage directory - for logs and pid files
- Bootstrap file (optional) - Allows you to add event listeners and extend storage
- Your workers
Below is an example:
<?xml version="1.0" encoding="UTF-8"?> <tomahawk storage="./storage" bootstrap="./queue-bootstrap.php"> <workers> <worker pidkey="emails" name="Emails" queues="emails" /> </workers> </tomahawk>
2. Create Bootstrap file
Bootstrap example file
<?php use Tomahawk\Queue\Application; use Tomahawk\Queue\Storage\StorageInterface; use Tomahawk\Queue\Storage\RedisStorage; use Predis\Client; use Pimple\Container; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Get the Autoloader */ require_once(__DIR__.'/vendor/autoload.php'); /** * Set Default Timezone */ date_default_timezone_set('Europe/London'); // Get the container $container = Application::getContainer(); // Set storage for jobs $container[StorageInterface::class] = function(Container $c) { $client = new Client([ 'scheme' => 'tcp', 'host' => '10.0.0.1', 'port' => 6379, ]); return new RedisStorage($client); }; $eventDispatcher = $container[EventDispatcherInterface::class]; // Add events $eventDispatcher->addListener(\Tomahawk\Queue\JobEvents::PROCESSED, function(\Tomahawk\Queue\Event\PreProcessEvent $event) { // Log to a file }); $container[EventDispatcherInterface::class];
Using the CLI
Create a new worker
./bin/tomahawk-queue work emails emails --daemon
Queue a new job to worker
./bin/tomahawk-queue queue emails JobClass {"id":"1"}
List running workers
./bin/tomahawk-queue list
Stop a running worker
./bin/tomahawk-queue stop emails
Load and run all workers defined in configuration file
./bin/tomahawk-queue load
Using the Queue Manager
If you have your works setup on a different VM or server you can still push jobs onto the queue using the Queue Manager.
Below is an example of how to do this
<?php use Predis\Client; use Tomahawk\Queue\Manager; use Tomahawk\Queue\Storage\RedisStorage; $client = new Client([ 'scheme' => 'tcp', 'host' => '10.0.0.1', 'port' => 6379, ]); $storage = new RedisStorage($client); $manager = new Manager($storage); $arguments = [ 'email' => '...', 'subject' => '...', ]; $manager->queue('queue_email', 'JobClass', $arguments);
License
Tomahawk Queue is open-sourced software licensed under the MIT license
tomahawk/queue 适用场景与选型建议
tomahawk/queue 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「worker」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tomahawk/queue 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tomahawk/queue 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tomahawk/queue 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Queue
PHP AMQP Binding Library
SlimQ Enables You to push jobs to background workers
A Laravel package to monitor queue jobs.
A lightweight task queue on top of rybakit/phive-queue
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-03-24