Skip to content

Commit 56898f8

Browse files
Add an inexpensive liveness check and make challenge/response optional
See #1742 and countless other persistent connection issues.
1 parent 80f2529 commit 56898f8

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

library.c

+7
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,13 @@ redis_sock_check_liveness(RedisSock *redis_sock)
18081808
struct timeval tv;
18091809
size_t len;
18101810

1811+
/* Check socket liveness using 0 second timeout */
1812+
if (php_stream_set_option(redis_sock->stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL) != PHP_STREAM_OPTION_RETURN_OK) {
1813+
return FAILURE;
1814+
} else if (!INI_INT("redis.pconnect.echo_check_liveness")) {
1815+
return SUCCESS;
1816+
}
1817+
18111818
if (redis_sock->auth) {
18121819
redis_cmd_init_sstr(&cmd, 1, "AUTH", sizeof("AUTH") - 1);
18131820
redis_cmd_append_sstr(&cmd, ZSTR_VAL(redis_sock->auth), ZSTR_LEN(redis_sock->auth));

redis.c

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ PHP_INI_BEGIN()
9090
/* redis pconnect */
9191
PHP_INI_ENTRY("redis.pconnect.pooling_enabled", "1", PHP_INI_ALL, NULL)
9292
PHP_INI_ENTRY("redis.pconnect.connection_limit", "0", PHP_INI_ALL, NULL)
93+
PHP_INI_ENTRY("redis.pconnect.echo_check_liveness", "1", PHP_INI_ALL, NULL)
9394

9495
/* redis session */
9596
PHP_INI_ENTRY("redis.session.locking_enabled", "0", PHP_INI_ALL, NULL)

0 commit comments

Comments
 (0)