php GearmanClient timeout


php GearmanClient timeout

我在php中使用gearman pecl扩展,并希望有一个函数调用的超时。两个用例:(1)没有运行worker, (2) worker需要很长时间才能完成

如果一切都在运行,则调用非常快,并且我希望避免这个超时的开销。

当前使用的代码:

$client = new GearmanClient();
$client->addServer();
$client->do('nonexistingfunction');

只需调用GearmanClient::setTimeout方法,并指定等待的毫秒数:

$client = new GearmanClient();
$client->addServer();
$client->setTimeout(5000);