Replies: 2 comments
-
The connect timeout is how long PhpRedis will wait for a successful connection before timing out. $redis = new Redis;
// If this takes more than 3.5 seconds, we will throw an exception
$redis->connect('localhost', 6379, 3.5); The read timeout has to do with how long Redis takes to respond to commands once connected. <?php
$redis = new Redis;
$redis->connect('localhost', 6379);
$redis->setOption(Redis::OPT_READ_TIMEOUT, 1);
Try {
$st = microtime(true);
$redis->rawCommand('DEBUG', 'sleep', 1.5);
} catch (Exception $ex) {
$et = microtime(true);
printf("Exception: '%s' (%f seconds)\n", $ex->getMessage(), $et - $st);
} Since the $ php read-timeout.php
Exception: 'socket error on read socket' (1.001548 seconds) |
Beta Was this translation helpful? Give feedback.
0 replies
-
thank you
…---- Replied Message ----
| From | Michael ***@***.***> |
| Date | 03/25/2025 01:50 |
| To | ***@***.***> |
| Cc | ***@***.***>***@***.***> |
| Subject | Re: [phpredis/phpredis] what does connect’s timeout and readtimeout mean? (Discussion #2640) |
The connect timeout is how long PhpRedis will wait for a successful connection before timing out.
$redis = newRedis;
// If this takes more than 3.5 seconds, we will throw an exception$redis->connect('localhost', 6379, 3.5);
The read timeout has to do with how long Redis takes to respond to commands once connected.
<?php$redis = newRedis;
$redis->connect('localhost', 6379);
$redis->setOption(Redis::OPT_READ_TIMEOUT, 1);
Try {
$st = microtime(true);
$redis->rawCommand('DEBUG', 'sleep', 1.5);
} catch (Exception$ex) {
$et = microtime(true);
printf("Exception: '%s' (%f seconds)\n", $ex->getMessage(), $et - $st);
}
Since the DEBUG SLEEP 1.5 command takes 1.5 seconds you should see an exception:
$ php read-timeout.php
Exception: 'socket error on read socket' (1.001548 seconds)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
timeout: float, value in seconds (optional, default is 0 meaning it will use default_socket_timeout)
What does the timeout of connect mean? for example, timeout is 3, means fail while connect not success in 3 seconds? or connect will disconnect after 3 seconds of idle?
Beta Was this translation helpful? Give feedback.
All reactions