Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to make a gearman PHP worker dont die if a server is not available? #344

Open
stccorp opened this issue Aug 28, 2022 · 6 comments
Labels

Comments

@stccorp
Copy link

stccorp commented Aug 28, 2022

I would like to create a worker that if gearman server is not running, that the worker just try to reconnects in X amount of seconds.

The problem that I have is that if I have 10 workers listening and I restart the gearman server, all the workers die, instead of waiting for gearman server to comeback.

Thank you

@esabol
Copy link
Member

esabol commented Aug 29, 2022

What language are your workers implemented in? C?

What version of gearmand are you using?

Does this happen using the gearman command line tool to create a worker? For example: gearman -w -f wordcount wc &?

This hasn't been my experience, but my workers are all implemented in Perl using this library. They don't die when gearmand is restarted and they automatically reconnect. I'm pretty sure that's true of PHP workers also.

@stccorp
Copy link
Author

stccorp commented Aug 29, 2022

Interesting, first time running gearman on the cli. Your were correct. if I run the worker and the kill gearman I get and infinate message
gearman: gearman_worker_work : flush(GEARMAN_COULD_NOT_CONNECT) Connection to localhost:4730 failed -> libgearman/connection.cc:724: pid(10320)

And when I start gearmand again, the process still there. So it seems that the problem is the php client library(maybe)

I am using gearmand 1.1.19.1+ds -

if I run the reverse example from gearman.org. It dies as soon as I stop gearmand

I am using PHP

root@test1:~/test# php -f worker.php
PHP Warning: GearmanWorker::work(): flush(GEARMAN_COULD_NOT_CONNECT) Connection to localhost:4730 failed -> libgearman/connection.cc:724: pid(10390) in /root/test/worker.php on line 8

@esabol
Copy link
Member

esabol commented Aug 29, 2022

I'm surprised to hear that PHP workers die when gearmand is stopped/killed. It might be a problem with the PHP Gearman library? Are you using https://github.com/php/pecl-networking-gearman/ ? Did you compile and install it yourself?

We have PHP Gearman clients at my job, but no workers are implemented in PHP, so I have no idea if this is expected behavior or not.

@stccorp
Copy link
Author

stccorp commented Aug 29, 2022

I am using Ubuntu. All I did to install gearman was
sudo apt install gearman

I checked the sources list and it has this line

deb http://ppa.launchpad.net/ondrej/pkg-gearman/ubuntu bionic main

@esabol
Copy link
Member

esabol commented Aug 29, 2022

I did some googling, and I found some things that might help:

https://stackoverflow.com/questions/14749576/gearman-throws-gearman-could-not-connect-on-php-example
https://stackoverflow.com/questions/22758869/gearman-workers-disconnect-periodicaly

The answer in that second link has a more complicated while loop than in our example code. You might want to try some variation of that that outputs the value of $worker->returnCode(). Maybe there's a return code that you can check for disconnects? This is all theoretical as I'm not a PHP programmer. (We don't maintain or distribute the PHP Gearman library. That's a separate project.)

Also, you might try asking on the Gearman mailing list: https://groups.google.com/g/gearman/

@stccorp
Copy link
Author

stccorp commented Aug 30, 2022

Thank you for the help. But nothing seems to work. What I am doing that other people do , is having a monitor so that when it dies, the monitor creates the workers again.

I will contact the gearman mailing list

Thank you

@esabol esabol changed the title Is there a way to make a gearman worker dont die if a server is not available? Is there a way to make a gearman PHP worker dont die if a server is not available? Sep 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants