我在php中使用gearman pecl扩展,并希望函数调用超时.两个用例:(1)没有正在运行的工人,(2)工人需要很长时间才能完成
如果一切正在运行,那么调用非常快,我想避免这个超时的开销.
我目前使用的代码:
$client = new GearmanClient();
$client->addServer();
$client->do('nonexistingfunction');
Run Code Online (Sandbox Code Playgroud)
小智 0
只需调用GearmanClient::setTimeout方法并指定要等待的毫秒数:
$client = new GearmanClient();
$client->addServer();
$client->setTimeout(5000);
Run Code Online (Sandbox Code Playgroud)