\Thread から継承するクラスのフィールドとして接続を使用すると、$this->connection->channel() 呼び出しで次のエラーが表示されます。
警告: fwrite() は、パラメーター 1 がリソースであると想定し、65 行目の /var/content-generator/PHP/vendor/videlvaro/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 の一部はありますか?