5

I'm using the gearman pecl extension in php, and want to have a timeout for a function call. Two use cases: (1) no running workers, (2) worker takes too long to complete

If everything is running, the call is very fast, and I want to avoid having an overhead for this timeout.

Code I currently use:

$client = new GearmanClient();
$client->addServer();
$client->do('nonexistingfunction');
IMSoP
  • 89,526
  • 13
  • 117
  • 169
Niko Sams
  • 4,304
  • 3
  • 25
  • 44
  • I have a related but slightly more complex use case, so have asked a new question here: https://stackoverflow.com/questions/49036819/get-response-from-multiple-jobs-in-gearman-but-abort-after-a-timeout/49049263 – IMSoP Mar 01 '18 at 12:30

1 Answers1

0

Just call GearmanClient::setTimeout method with number of milliseconds to wait:

$client = new GearmanClient();
$client->addServer();
$client->setTimeout(5000);
Jake McGraw
  • 55,558
  • 10
  • 50
  • 63
Eugene Leonovich
  • 884
  • 1
  • 9
  • 15