当使用连接作为继承自 \Thread 的类的字段时,我在 $this->connection->channel() 调用中收到以下错误:
警告:fwrite() 期望参数 1 是资源,整数在第 65 行的 /var/content-generator/PHP/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php 中给出
如果我使用本地变量,一切正常,但我一转到现场电话就收到错误消息。
失败代码:
public function run()
{
$this->run = true;
echo ' Thread-'.$this->ThreadId." including", "\n";
require_once($this->loader);
$this->connection = GetRabbitConnection();
echo ' Thread-'.$this->ThreadId." opening channel", "\n";
$this->channel = $this->connection->channel();
echo ' Thread-'.$this->ThreadId." getting queue data", "\n";
$RedisClient = GetRedisClient();
$ScrapeExchange = $RedisClient->get(Scrape.":".Exchange);
$ScrapeQueue = $RedisClient->get(Scrape.":".Queue);
$this->OutboundExchange = $RedisClient->get(Extract.":".Exchange);
$this->OutboundRoutingKey = $RedisClient->get(Extract.":".RoutingKey);
$RedisClient = null;
echo ' Thread-'.$this->ThreadId." consuming", "\n";
$this->channel->basic_qos(0,1,false);
$this->channel->basic_consume($ScrapeQueue, $ScrapeExchange, false, true, false, false, array($this, 'ProcessMessage'));
while($this->run) {
$this->channel->wait();
}
$this->channel->close();
}
工作代码:
public function run()
{
echo ' Thread-'.$this->ThreadId." including", "\n";
require_once($this->loader);
echo ' Thread-'.$this->ThreadId." building connection", "\n";
$connection = GetRabbitConnection();
echo ' Thread-'.$this->ThreadId." opening channel", "\n";
$channel = $connection->channel();
echo ' Thread-'.$this->ThreadId." getting queue data", "\n";
$RedisClient = GetRedisClient();
$ScrapeExchange = $RedisClient->get(Scrape.":".Exchange);
$ScrapeQueue = $RedisClient->get(Scrape.":".Queue);
$this->OutboundExchange = $RedisClient->get(Extract.":".Exchange);
$this->OutboundRoutingKey = $RedisClient->get(Extract.":".RoutingKey);
$RedisClient = null;
echo ' Thread-'.$this->ThreadId." consuming", "\n";
$channel->basic_consume($ScrapeQueue, $ScrapeExchange, false, true, false, false, array($this, 'ProcessMessage'));
while(true) {
$channel->wait();
}
$channel->close();
$connection->close();
}
我错过了什么?我缺少一些 \Thread 或 pthreads 吗?