nicolasff/phpredis — pull request #260 by kotas (2012-10-04 13:57:13+00:00)
Title: add Redis::OPT_READ_TIMEOUT option for issue #70

This is a patch to fix issue [#70 debug read error on connection](https://github.com/nicolasff/phpredis/issues/70).

`Redis#connect()` uses its third argument `timeout` not only for the connection timeout but also for the read timeout on an opened stream. (by calling `php_stream_set_option` on the stream)

This behavior causes "read error" on any reading methods (get, hget, blpop, etc.) if you give very short timeout value to `connect()`.

This patch adds `Redis::OPT_READ_TIMEOUT` for `Redis#setOption()` so that you can specify another timeout value for `php_stream_set_option`.

You can test this fix by @micharl-grunder's [reproduce code](https://github.com/nicolasff/phpredis/issues/70#issuecomment-5096151).

### Before
```php
try {
$r = new Redis();
if(!$r->connect('localhost',6379,5)) {
echo "Couldn't connect\n";
die();
}
$st = microtime(true);
$val = $r->blpop('mykey',0);
$et = microtime(true);
} catch(Exception $ex) {
echo "ex: " . $ex->getMessage() . "\n";
$et = microtime(true);
}

echo "Took: " . ($et-$st) . " to get the key\n";
```
output:
```
ex: read error on connection
Took: 5.0015189647675 to get the key
```

### After
```php
try {
$r = new Redis();
if(!$r->connect('localhost',6379,5)) {
echo "Couldn't connect\n";
die();
}
$r->setOption(Redis::OPT_READ_TIMEOUT, 10); // by patch
$st = microtime(true);
$val = $r->blpop('mykey',0);
$et = microtime(true);
} catch(Exception $ex) {
echo "ex: " . $ex->getMessage() . "\n";
$et = microtime(true);
}

echo "Took: " . ($et-$st) . " to get the key\n";
```
output:
```
ex: read error on connection
Took: 10.001543998718 to get the key
```