php / pecl-networking-gearman

PHP wrapper to libgearman
https://pecl.php.net/package/gearman
Other
33 stars 25 forks source link

GearmanWorker throws "GearmanException: Failed to set exception option" on addServer #7

Closed microlancer closed 1 year ago

microlancer commented 3 years ago

Hello,

In the previous repository, there was an issue around addServer making connections for \GearmanClient which was resolved with a new 3rd parameter. (See https://github.com/wcgallego/pecl-gearman/issues/59)

Is there any plan to also support this for addServer() and addServers() for the \GearmanWorker class as well? I was able to migrate my code to use the 3rd parameter for \GearmanClient and avoided the GearmanException: Failed to set exception option for that case.

However, for \GearmanWorker I'm still getting an error.

PHP Fatal error:  Uncaught GearmanException: Failed to set exception option in Gearman.php:33                                                                  
Stack trace:                                                                              
#0 /home/dev/app/Util/Gearman.php(33): GearmanWorker->addServer('127.0.0.1', 4730)

And trying to add the 3rd parameter (set to false), I am getting:

Warning: GearmanWorker::addServer() expects at most 2 parameters, 3 given in /home/dev/app/Util/Gearman.php on line 33

gearman extension version => 2.1.0 libgearman version => 1.1.19.1

Thanks for any input!

oleg-st commented 3 years ago

Added PR for this feature

ifohancroft commented 2 years ago

To avoid getting a fatal error from PHP, I putt my $worker->addServer() call inside of a try catch block and it helps, however, I still never get inside of the catch (Throwable) (I've tried with Throwable, Error, Exception, etc). Is that a problem with Gearman or am I missing/not understanding something.

esabol commented 2 years ago

To avoid getting a fatal error from PHP, I putt my $worker->addServer() call inside of a try catch block and it helps, however, I still never get inside of the catch (Throwable) (I've tried with Throwable, Error, Exception, etc). Is that a problem with Gearman or am I missing/not understanding something.

I don't think this question is relevant to this issue. addServer() returns true or false, so you use it like this:

if ($worker->addServer($host, $port) !== true) {
   exit(1); // or handle error somehow
};

Or like this:

if (! $worker->addServer($host, $port)) {
   exit(1); // or handle error somehow
};

That said, if some exception were to be thrown, the PHP extension registers the class GearmanException for doing so. See https://github.com/php/pecl-networking-gearman/blob/69d6b78374fc9914906ecaea0fe919b6903cd526/php_gearman.c#L123

ifohancroft commented 2 years ago

It returns true or false but apparently on some PHP versions (between 7 and 8, I think) if you don't put it in a try catch block, php dies with a fatal error about an uncaught exception, however, putting it in a try catch block, the catch blocking doesn't catch anything, but the fact that it is in a 'try' prevents PHP from dying with an error.