ConFoo Montreal 2026: Call for Papers

Voting

: three minus two?
(Example: nine)

The Note You're Voting On

iloveapplepie
3 years ago
Sometimes you want the job server to start even if not all servers are available. The reason is that if at a later point the server comes back gearman will use it, even if if failed during the add server operation.

class SmartGearmanWorker extends GearmanWorker
{
function addServer($host = '127.0.0.1', $port = 4730):bool
{
try {
parent::addServer($host, $port);
echo "\nSERVER $host WORKED";
} catch (GearmanException $e) {
echo "\nSERVER $host FAILED";
}
return true;
}
}

class SmartGearmanClient extends GearmanClient
{
function addServer($host = '127.0.0.1', $port = 4730, bool $setupExceptionHandler = false):bool
{
try {
parent::addServer($host, $port, $setupExceptionHandler);
echo "\nSERVER $host WORKED";
} catch (GearmanException $e) {

echo "\nSERVER $host FAILED"; //this does not get called even if the server is down
}
return true;
}
}

<< Back to user notes page

To Top