Credis_Client::setReadTimeout PHP Method

setReadTimeout() public method

Set the read timeout for the connection. Use 0 to disable timeouts entirely (or use a very long timeout if not supported).
public setReadTimeout ( integer $timeout ) : Credis_Client
$timeout integer 0 (or -1) for no timeout, otherwise number of seconds
return Credis_Client
    public function setReadTimeout($timeout)
    {
        if ($timeout < -1) {
            throw new CredisException('Timeout values less than -1 are not accepted.');
        }
        $this->readTimeout = $timeout;
        if ($this->connected) {
            if ($this->standalone) {
                $timeout = $timeout <= 0 ? 315360000 : $timeout;
                // Ten-year timeout
                stream_set_blocking($this->redis, TRUE);
                stream_set_timeout($this->redis, (int) floor($timeout), ($timeout - floor($timeout)) * 1000000);
            } else {
                if (defined('Redis::OPT_READ_TIMEOUT')) {
                    // supported in phpredis 2.2.3
                    // a timeout value of -1 means reads will not timeout
                    $timeout = $timeout == 0 ? -1 : $timeout;
                    $this->redis->setOption(Redis::OPT_READ_TIMEOUT, $timeout);
                }
            }
        }
        return $this;
    }

Usage Example

Example #1
0
 public function testReadTimeout()
 {
     $this->credis->setReadTimeout(0.0001);
     try {
         $this->credis->save();
         $this->fail('Expected exception (read should timeout since disk sync should take longer than 0.0001 seconds).');
     } catch (CredisException $e) {
     }
     $this->credis->setReadTimeout(10);
 }
All Usage Examples Of Credis_Client::setReadTimeout