Velaro
Velaro

Reputation: 501

PHP GearmanClient::doBackground just hangs

Mehod doBackground of GearmanClient and its descendants such as doLowBackground and doHighBackground sometimes hang. I cannot figure out why.

php 5.4

Gearman server version 1.1.18

Gearman php lib version 1.1.2

At some point of time user clicks the button, and tasks (more than 700) go to the gearman. DoBackground freezes randomly, it can hang after 20 task put into gearman, or can hang after 200-300, maybe 500 tasks.

I don't see errors in gearman/php logs nor see in direct link (when I directly start debugging)

When I try to debug, I just minimize tasks count to 50, and issue request directly from browser. If everything goes well, browser's circle (loading action) dissapears, and I see my var_dumps. But if at some task doBackground didnt return control, browser request goes to infinite loop, waiting server response

My code is simple. I collect data, put into array, and one by one send to queue

for($i = 0; $i < count($itemsToProcess); $i++) {var_dump($i);
    $method = array_shift($itemsToProcess[$i]['methodsAfter']);
    Yii::app()->gearman->client()->doBackground($method, json_encode($itemsToProcess[$i]));
}

As additional information, I have another server with

php 7.1

installed,

server version is 1.1.12

, and

libgearman for php was auto installed with yum

. There seems to be same problem, but!!! it appears very very rarely.

Of course it's crucial and very critical problem, if you issue A count and B count goes into queue.

P.S: The reason of different enviroments is that we cannot still migrate to php7. Php5.4 is prod and php7 is dev

Upvotes: 1

Views: 456

Answers (2)

N&#228;tu
N&#228;tu

Reputation: 332

The Client initialization should happen out of the loop. I faced the same issue. Memory gets exhausted when you initiate within the loop. Hope this helps you!

https://stackoverflow.com/a/54442341/4932684

Upvotes: 1

Velaro
Velaro

Reputation: 501

It's not gearmand, nor php extension problem

https://github.com/gearman/gearmand/issues/241

Upvotes: 1

Related Questions