Skip to content

Commit 7120d80

Browse files
authored
Set TCP_NODELAY when setting binary protocol (#421)
* Set TCP_NODELAY when setting binary protocol * Add braces to the check_set_behavior macro
1 parent a452d9a commit 7120d80

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

php_memcached.c

+5
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,11 @@ static PHP_METHOD(Memcached, __construct)
12861286
if (rc != MEMCACHED_SUCCESS) {
12871287
php_error_docref(NULL, E_WARNING, "Failed to turn on binary protocol: %s", memcached_strerror(intern->memc, rc));
12881288
}
1289+
/* Also enable TCP_NODELAY when binary protocol is enabled */
1290+
rc = memcached_behavior_set(intern->memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
1291+
if (rc != MEMCACHED_SUCCESS) {
1292+
php_error_docref(NULL, E_WARNING, "Failed to set TCP_NODELAY: %s", memcached_strerror(intern->memc, rc));
1293+
}
12891294
}
12901295

12911296
if (MEMC_G(default_behavior.connect_timeout)) {

php_memcached_session.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ void s_unlock_session(memcached_st *memc)
178178
static
179179
zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
180180
{
181+
/* This macro looks like a function but returns errors directly */
181182
#define check_set_behavior(behavior, value) \
183+
{ \
182184
int b = (behavior); \
183185
uint64_t v = (value); \
184186
if (v != memcached_behavior_get(memc, b)) { \
@@ -189,10 +191,13 @@ zend_bool s_configure_from_ini_values(memcached_st *memc, zend_bool silent)
189191
} \
190192
return 0; \
191193
} \
192-
}
194+
} \
195+
}
193196

194197
if (MEMC_SESS_INI(binary_protocol_enabled)) {
195198
check_set_behavior(MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
199+
/* Also enable TCP_NODELAY when binary protocol is enabled */
200+
check_set_behavior(MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
196201
}
197202

198203
if (MEMC_SESS_INI(consistent_hash_enabled)) {

0 commit comments

Comments
 (0)