hosopy / fuel-jobqueue
FuelPHP 任务队列包
dev-master
2013-09-11 06:02 UTC
Requires
- php: >=5.3.3
- composer/installers: *
- pda/pheanstalk: *
- symfony/process: 2.3
This package is not auto-updated.
Last update: 2024-09-23 14:10:25 UTC
README
FuelPHP 任务队列包。
要求
- PHP 5.3.3+
- symfony/Process 2.3
- pda/pheanstalk
- beanstalkd
安装
A: 使用 composer
将所需包添加到您的 composer.json。
... "require": { ... "hosopy/fuel-jobqueue": "dev-master", ... }, ...
然后运行 composer 安装器。
$ php composer.phar install
B: 手动
下载 zip 存档或克隆此存储库,并将其解压到 fuel/app/packages/fuel-jobqueue。
使用方法
1. 启用包
'always_load' => array( 'packages' => array( 'fuel-jobqueue', ...
2. 配置
将默认配置文件复制到您的应用配置目录。
$ cp fuel/packages/fuel-jobqueue/config/jobqueue.php fuel/app/config
如果您想在其他机器或端口上运行 beanstalkd,请编辑配置。
目前,请保持默认配置。
return array( // default connection name 'default' => 'default_connection', 'connections' => array( 'default_connection' => array( 'driver' => 'beanstalkd', 'host' => '127.0.0.1', 'port' => '11300', 'queue' => 'jobqueue', ), ), );
3. 安装并运行 beanstalkd
目前,fuel-jobqueue 使用 beanstalkd 作为队列的底层。
如果您的机器上未安装 beanstalkd,请先安装它。
# Example: homebrew (Mac)
$ brew install beanstalkd
$ beanstalkd
# Example: Ubuntu
$ sudo apt-get install beanstalkd
如果您想了解更多关于 beanstalkd 的信息,请参阅 。
4. 定义任务
在 fuel/app/classes/myjob.php 中定义您的任务处理类。
<?php class Myjob { // [IMPORTANT] Requires 'fire' method as a entry point. public function fire($job, $data) { // heavy job sleep(10); } }
5. 队列任务
在您的控制器中,调用 \Jobqueue\Queue::push($job, $data) 以推送新任务。
class Controller_Welcome extends Controller { public function action_index() { // push a new job onto the default queue of the default connection. // 'Myjob' is a class name you have defined. \Jobqueue\Queue::push('Myjob', array('message' => 'Hello World!')); return Response::forge(View::forge('welcome/index')); } ...
6. 运行工作进程任务
队列中的任务必须等到工作进程从队列中取出它们才能执行。
$ cd FUEL_ROOT
$ php oil refine jqworker:listen --connection=default_connection --queue=jobqueue
7. 执行控制器操作
现在,我们已经准备好进行队列处理!
执行您的控制器操作。
配置
抱歉,正在建设中...
任务
抱歉,正在建设中...
队列
抱歉,正在建设中...
任务
抱歉,正在建设中...