treehouselabs/worker-bundle
最新稳定版本:2.0.1
Composer 安装命令:
composer require treehouselabs/worker-bundle
包简介
Adds worker functionality to a Symfony2 project, using Beanstalkd as the message queue
关键字:
README 文档
README
This bundle is no longer maintained. It will still work with Symfony versions ^2.8|^3.0|^4.0 and is archived here to not break existing applications using it. However it will not get maintenance updates or even security fixes.
If you need queue/worker functionality in your project, there are far better solutions right now to look at:
Previous readme below 👇
Worker bundle
A Symfony bundle that adds worker functionality to your project, using Beanstalkd as the message queue.
Installation
For this process, we assume you have a Beanstalk server up and running.
Install via Composer:
$ composer require treehouselabs/worker-bundle
Enable the bundle:
# app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = [ // ... new TreeHouse\WorkerBundle\TreeHouseWorkerBundle(), ]; // ... } // ... }
Configuration
Define a queue and you're good to go:
# app/config/config.yml tree_house_worker: queue: server: localhost
The bundle also supports the PheanstalkBundle, if you're using that:
# app/config/config.yml tree_house_worker: pheanstalk: leezy.pheanstalk
Basic Usage
The bundle creates a QueueManager service, which you can use to manage
jobs. The manager has services registered to execute specific tasks, called
executors. An executor receives a job from the QueueManager and processes it.
Defining executors
First you need to register an executor, and tag it as such:
# src/AppBundle/Executor/HelloWorldExecutor.php use TreeHouse\WorkerBundle\Executor\AbstractExecutor; class HelloWorldExecutor extends AbstractExecutor { public function getName() { return 'hello.world'; } public function configurePayload(OptionsResolver $resolver) { $resolver->setRequired(0); } public function execute(array $payload) { $name = array_shift($payload); # process stuff here, in this example we just print something echo 'Hello, ' . $name; return true; } }
# app/config/services.yml app.executor.hello_world: class: AppBundle/Executor/HelloWorldExecutor tags: - { name: tree_house.worker.executor }
Scheduling jobs
Now you can add jobs, either via code or using the worker:schedule command:
In your application's code:
$queueManager = $container->get('tree_house.worker.queue_manager'); $queueManager->add('hello.world', ['Peter']);
Using the command:
php app/console worker:schedule hello.world Peter
Working jobs
A worker can now receive and process these jobs via the console:
php app/console worker:run
# prints:
# Working hello.world with payload ["Peter"]
# Hello, Peter
# Completed job in 1ms with result: true
You can run workers by adding them to your crontab, creating a Supervisor program for it, or whatever your preferred method is.
Documentation
Security
If you discover any security related issues, please email dev@treehouse.nl instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
Credits
treehouselabs/worker-bundle 适用场景与选型建议
treehouselabs/worker-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 57.75k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2015 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「beanstalk」 「worker」 「beanstalkd」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 treehouselabs/worker-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 treehouselabs/worker-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 treehouselabs/worker-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Queue
A simple bundle that integrate Pheanstalk with Symfony
$queue->push('I can be popped off after', '10 minutes');
PHP7.1+ client for beanstalkd work queue with no dependencies
Library for handling beanstalk connections.
SlimQ Enables You to push jobs to background workers
统计信息
- 总下载量: 57.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-23