многопоточность — ошибка PHP AMQP (не phpamqplib) при использовании потока

Я пытаюсь превратить простой клиент AMQP в многопоточность. Следующий код работает, если я не расширяю Publish with Thread:

<?php

include ('../JS-amqp-include.php');

$mypid = getmypid();

echo "PID: $mypid\n";

class Publish extends Thread {

private $co;// connection
private $ch;// channel
private $ex;// exchange
private $mypid, $thread_id;

public function __construct($connection = '') {
$this->mypid = getmypid();

$this->co = new AMQPConnection();
$this->co->setHost(HOST);
$this->co->setLogin(USER);
$this->co->setPassword(PASS);
$this->co->setVHost(VHOST);
$this->co->connect();           // <-- Fail here!!!!

$this->ch = new AMQPChannel($this->co);

$this->ex = new AMQPExchange($this->ch);
$this->ex->setName(X_DIR);
$this->ex->setType(XT_DIR);
$this->ex->setFlags(AMQP_DURABLE);
$this->ex->declareExchange();
}

public function run($cycle = 10, $input = '') {
for ($i = 1; $i <= $cycle; $i++) {
$msg = $this->mypid.':'.$input.':'.$i;
$this->ex->publish($msg);
}
}
}

$time_start = microtime(true);

$pub = new Publish();
$pub->run(100, 'thread');
$time_end      = microtime(true);
$time_duration = $time_end-$time_start;
echo "Duration: $time_duration Sec.\n";

?>;

Ниже выводится с ошибкой:

PID: 2276
PHP Fatal error:  Uncaught exception 'AMQPConnectionException' with message 'Socket error: could not connect to host.' in /home/john/rmq/php/Amqp/JS-amqp-publish-thread.php:24
Stack trace:
#0 /home/john/rmq/php/Amqp/JS-amqp-publish-thread.php(24): AMQPConnection->connect()
#1 /home/john/rmq/php/Amqp/JS-amqp-publish-thread.php(45): Publish->__construct()
#2 {main}
thrown in /home/john/rmq/php/Amqp/JS-amqp-publish-thread.php on line 24

У кого-нибудь есть идея, почему это происходит или как это исправить?

Rabbitmq работает на хосте.

Программа работает отлично, если ‘extends Thread’ удален из объявления класса Publish. Приведенный выше код даже не использует поток. Я просто расширяю класс, и он ломается.

Системная информация

ОС: Ubuntu 15.10

Rabbitmq-c (apt-get install)

librabbitmq-dev: amd64 0.5.2-2 amd64 Клиентская библиотека AMQP, написанная на C — Dev Files
librabbitmq1: amd64 0.5.2-2 amd64 Клиентская библиотека AMQP, написанная на C

Я следую за этим ссылка на сайт перекомпилировать пакет Ubuntu PHP для поддержки ZTS.

PHP 5.6.11-1ubuntu3.2 (cli)

Copyright (c) 1997-2015 The PHP Group

Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies с Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, Zend Technologies

Модуль PHP

Amqp 1.6.0 стабильный

pthreads 2.0.10 стабильный

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector