我在Centos 6上安装了Laravel和phanstalkd包:
"laravel/framework": "4.*",
"pda/pheanstalk": "~2.1"
我的Laravel队列配置文件是:
return array(
'default' => 'beanstalkd',
'connections' => array(
'beanstalkd' => array(
'driver' => 'beanstalkd',
'host' => 'localhost',
'queue' => 'default',
'ttr' => 60,
),
...
),
);
Beanstalked已经安装并启动,并且Supervisor已经配置了以下内容:
[program:website]
command=php artisan queue:listen --env=production
process_name=%(program_name)s_%(process_num)02d
priority=999
autorestart=true
directory=/var/www/html/
stdout_logfile=/var/www/html/app/storage/logs/website_supervisord.log
numprocs=5
numprocs_start=5
startsecs=0
autostart=true
redirect_stderr=true
[program:testing]
command=php artisan queue:listen --env=production
process_name=%(program_name)s_%(process_num)02d
priority=999
autorestart=true
directory=/var/www/html/
stdout_logfile=/var/www/html/app/storage/logs/testing_supervisord.log
numprocs=5
numprocs_start=5
startsecs=0
autostart=true
redirect_stderr=true
网站和测试组添加并工作
队列"default"是执行我的工作的队列,我需要多个队列在应用程序中工作(如我的网站和在主管中创建的测试程序)。我试过了:
Queue::push('TheBigTest', array('message' => $message), 'website');
但运气不好:(
关于类调用的更多细节如下:
<?php
class TheBigTest {
public function fire($job, $data)
{
if ($job->attempts() >= 0){
$job->delete();
}
$nr = 1000;
for ($i=0;$i<=$nr;$i++){
$newDummy = new Dummy;
$newDummy->nr = $i;
$newDummy->other = $i*32;
$newDummy->save();
}
$debug = new Debug;
$test = $job->getPheanstalk()->stats();
$debug->job_execution = $test["rusage-stime"];
$debug->job_time = $test["rusage-utime"];
$debug->pid = $test["pid"];
$debug->uptime = $test["uptime"];
$debug->job_id = $test["id"];
$debug->max_job_size = $test["max-job-size"];
$debug->current_tubes = $test["current-tubes"];
$debug->current_connections = $test["current-connections"];
$debug->current_workers = $test["current-workers"];
$debug->current_waiting = $test["current-waiting"];
$debug->total_connections = $test["total-connections"];
$debug->total_jobs = $test["total-jobs"];
$debug->job_timeouts = $test["job-timeouts"];
$debug->debug = json_encode($job->getPheanstalk()->listTubeUsed());
$debug->save();
}
}
其他配置还没有完成,我不知道如何在其他队列上运行
从我对文档的阅读来看,Queue::push
的第三个参数似乎是一个队列名称(否则它将使用连接中设置的名称,这里是default
)。所以你把它放入管website
,但不是从队列读取。如果您显示正在使用的所有管道的列表(在telnet中直接使用命令list-tubes
,或等效的Laravel Queues库),您将看到其中有作业的其他管道名称(除了'default')。