【发布时间】:2015-03-03 13:32:59
【问题描述】:
我为 Beanstalkd 队列编写了我的消费者,使用 Supervisord 运行它。
php5.5-sp %appdir%/worker
worker 是一个 PHP 文件,以 1 秒的睡眠时间循环。比如:
#!/usr/bin/env php
<?php
while(true)
{
echo time() . PHP_EOL;
exec("php5.5-sp -d max_execution_time=30 job");
sleep(1);
}
job(文件)使用 Beanstalkd,弹出一个作业,尝试处理它。
// job
require __DIR__.'/vendor/autoload.php';
# Initialize beanstalkd
$beanstalkd = new Illuminate\Queue\Worker($queue->getQueueManager(), null, null);
try {
$beanstalkd ->pop('default', 'default', 2, 8192);
} catch (Exception $e) {
Log::critical($e->getMessage());
}
queue 是这样的:
<?php namespace Aristona\Queue;
class ArticleParserService
{
public function fire($job, Array $data)
{
// Do some time taking stuff
}
}
一切正常。问题是,有时我希望超时(例如,我尝试获取的站点有一个重定向循环)但队列只是一直运行下去。由于它没有停止,其余的队列都被阻塞了。
我试过了:
添加
-d max_execution_time=30,无效。在队列上设置
max_execution_time,无效。在 Beanstalkd 配置上将
ttr设置为 30 秒,无效。
我不知道我还应该做什么?
日志是这样的:
sudo supervisord > tail -f queue
Worker is looping on [production] at 1425389013...
Worker is looping on [production] at 1425389016...
Worker is looping on [production] at 1425389017...
Worker is looping on [production] at 1425389019...
Worker is looping on [production] at 1425389023...
Worker is looping on [production] at 1425389027... (stuck here forever)
vi debug.log
DEBUG - 2015-03-03 08:23:59 :: There is no image in the feed. Attempting to guess it.
DEBUG - 2015-03-03 08:23:59 :: Guessing image from URL: https://www.aksent-tercume.com/di%c4%9fer-diller/212-dilde-seni-seviyorum-de/
DEBUG - 2015-03-03 08:24:01 :: Guessed an appropriate image!
DEBUG - 2015-03-03 08:24:01 :: Validating image size...
带有“正在验证图像大小...”的部分,一切都永远停止,并且始终位于同一个 URL 中。 (https://www.aksent-tercume.com/di%c4%9fer-diller/212-dilde-seni-seviyorum-de/)
脚本所做的只是连接到一个 URL,为文章找到最合适的图像,然后检查它的大小以确保它大于 60x60 像素。但由于某种原因,它只是停在那里,永远阻塞了我们的队列。我无法让它超时。只有以下使队列恢复正常。
sudo service beanstalkd restart
sudo supervisorctl > restart all
有什么想法吗?
【问题讨论】:
标签: php multithreading queue beanstalkd