gjedeer / celery-php

PHP client for Celery
http://massivescale.net/celery-php/
Other
422 stars 120 forks source link

Broker connection still open #76

Closed Zeniox closed 7 years ago

Zeniox commented 8 years ago

Hi!!

I have a problem, with rabbitq as broker, I see in RabbitMQ Management (in Connections tab) my php script leave always one connection open in every server call.

I will try to explain myself, sorry for my awful english.

My requirements are very simple, my tasks dosen´t need confirmations and I don´t need results tasks, in fact, Celery is working without backend track, I mean: CELERY_RESULT_BACKEND = 'disabled://'

So my typical scenario is like:

.
.
.
$celery = new Celery('localhost','guest','guest','/');
$celery->PostTask("myuntrackedtask", $m_param , false);
.
.
(more my php stuff regardless of celery's world...)
.
.

I see in the RabbitMQ Management tab as connections opens, one for broker and one for backend (although I do not need backend), when the php script is finished one connection is closed but another one is still open... and accumulate along the time many open connections.

Please.. can anybody help me?

Thanks very much!!

Zeniox

gjedeer commented 8 years ago

You could try explicitly destroying the object by calling uset($celery).

But maybe you could try using another backend (php-amqplib instead of PECL AMQP, or vice versa) - the back end library is supposed to close connections when the script finishes execution, if it does not, it's a bug.

For details on why we're not closing connections explicitly after posting a task, see https://github.com/gjedeer/celery-php/pull/62

Zeniox commented 8 years ago

Thanks for your reply gjedeer ;)

Oh no, this is more simple, I traced the execution and find out this. (sorry for my awful english)

In celery.php , inside of BuildConnection function , the $this->isConnected class variable not is set to true , then in the PostTask function, in this lines...

if (!$this->isConnected) {
 $this->broker_amqp->Connect($this->broker_connection);
 $this->isConnected = true;
}

The script unknowns the opened connection and open another connection (two open connections now). So, when the script ends, PECL AMQP, library close one connection, but the first (or the last i don´t know) is still open.. forever.

My solution??, in BuildConnection function, set $this->isConnected to true and works fine, obviously ;)

Thanks for your support gjedeer, and sorry for my delayed response, in this days i'm very busy...

jdufresne commented 7 years ago

@Zeniox the latest release, 2.1.2, has fixes with regards to reusing an open Celery connection. Can you upgrade and see if you're still experiencing the same issue. If so, could you provide a minimal test script that demonstrates the buggy behavior?

jdufresne commented 7 years ago

Closing until requested information is provided. If you can provide a minimal test script demonstrating the bug with the latest release or master branch, please reopen.