Skip to content

Set TCP_NODELAY when setting binary protocol #421

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,11 @@ static PHP_METHOD(Memcached, __construct)
if (rc != MEMCACHED_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to turn on binary protocol: %s", memcached_strerror(intern->memc, rc));
}
/* Also enable TCP_NODELAY when binary protocol is enabled */
rc = memcached_behavior_set(intern->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
if (rc != MEMCACHED_SUCCESS) {
php_error_docref(NULL, E_WARNING, "Failed to set TCP_NODELAY: %s", memcached_strerror(intern->memc, rc));
}
}

if (MEMC_G(default_behavior.connect_timeout)) {
Expand Down
7 changes: 6 additions & 1 deletion php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ void s_unlock_session(memcached_st *memc)
static
zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
{
/* This macro looks like a function but returns errors directly */
#define check_set_behavior(behavior, value) \
{ \
int b = (behavior); \
uint64_t v = (value); \
if (v != memcached_behavior_get(memc, b)) { \
Expand All @@ -189,10 +191,13 @@ zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
} \
return 0; \
} \
}
} \
}

if (MEMC_SESS_INI(binary_protocol_enabled)) {
check_set_behavior(MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
/* Also enable TCP_NODELAY when binary protocol is enabled */
check_set_behavior(MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
}

if (MEMC_SESS_INI(consistent_hash_enabled)) {
Expand Down