略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: GearmanClient::setTimeout

2024-12-22

GearmanClient::setTimeout

(PECL gearman >= 0.6.0)

GearmanClient::setTimeoutSet socket I/O activity timeout

说明

public GearmanClient::setTimeout(int $timeout): bool

Sets the timeout for socket I/O activity.

参数

timeout

An interval of time in milliseconds

返回值

Always returns true.

add a noteadd a note

User Contributed Notes 3 notes

up
3
Ismael Cristal Jr
9 years ago
GearmanClient has a default timeout of -1 you need to set this to a positive number using setTimeout to avoid cases where your script waits forever to run a job even if there are no workers running at all.
up
2
casper at bcx dot nl
4 years ago
If a timeout is set with this method, and a timeout occurred, calling ->returnCode() will return GEARMAN_TIMEOUT

Beware that a timeout of for example a doBackground() call does not mean the job did not start. It's very possible the job got submitted and started but the gearmand server was not able to communicate that information back to you.
up
-1
luckyboy449 at yahoo dot com
2 years ago
Note that GEARMAN_TIMEOUT is mostly triggered when you use a callback with the addTask() and addTaskBackground() methods. If the Gearman server is not able to answer under high volume of jobs  about the status of the current job, the client will certainly throw a GEARMAN_TIMEOUT error.

The safest way to escape this error is using the doBackground() method especially when you are not interested to find the status of the job (failed or completed) and that should be a rule when you are sending high volume of jobs to the server.

官方地址:https://www.php.net/manual/en/gearmanclient.settimeout.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3