mirror of
https://github.com/php-win-ext/pecl-memcache.git
synced 2026-03-24 00:52:07 +01:00
Added INI directive memcache.compress_threshold = 20000 which controls the default compression threshold
Added E_NOTICE when receiving out-of-memory or object-to-large errors
This commit is contained in:
22
memcache.c
22
memcache.c
@@ -220,6 +220,20 @@ static PHP_INI_MH(OnUpdateRedundancy) /* {{{ */
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
static PHP_INI_MH(OnUpdateCompressThreshold) /* {{{ */
|
||||
{
|
||||
long int lval;
|
||||
|
||||
lval = strtol(new_value, NULL, 10);
|
||||
if (lval < 0) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.compress_threshold must be a positive integer ('%s' given)", new_value);
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
return OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/* {{{ PHP_INI */
|
||||
PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY("memcache.allow_failover", "1", PHP_INI_ALL, OnUpdateLong, allow_failover, zend_memcache_globals, memcache_globals)
|
||||
@@ -231,6 +245,7 @@ PHP_INI_BEGIN()
|
||||
STD_PHP_INI_ENTRY("memcache.hash_function", "crc32", PHP_INI_ALL, OnUpdateHashFunction, hash_function, zend_memcache_globals, memcache_globals)
|
||||
STD_PHP_INI_ENTRY("memcache.redundancy", "1", PHP_INI_ALL, OnUpdateRedundancy, redundancy, zend_memcache_globals, memcache_globals)
|
||||
STD_PHP_INI_ENTRY("memcache.session_redundancy", "2", PHP_INI_ALL, OnUpdateRedundancy, session_redundancy, zend_memcache_globals, memcache_globals)
|
||||
STD_PHP_INI_ENTRY("memcache.compress_threshold", "20000", PHP_INI_ALL, OnUpdateCompressThreshold, compress_threshold, zend_memcache_globals, memcache_globals)
|
||||
PHP_INI_END()
|
||||
/* }}} */
|
||||
|
||||
@@ -364,6 +379,7 @@ int mmc_stored_handler(mmc_t *mmc, mmc_request_t *request, int response, const c
|
||||
if (param != NULL && Z_TYPE_P((zval *)param) == IS_NULL) {
|
||||
ZVAL_TRUE((zval *)param);
|
||||
}
|
||||
|
||||
return MMC_REQUEST_DONE;
|
||||
}
|
||||
|
||||
@@ -372,6 +388,12 @@ int mmc_stored_handler(mmc_t *mmc, mmc_request_t *request, int response, const c
|
||||
if (param != NULL) {
|
||||
ZVAL_FALSE((zval *)param);
|
||||
}
|
||||
|
||||
if (response != MMC_RESPONSE_EXISTS) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Server %s (tcp %d, udp %d) failed with: %s (%d)",
|
||||
mmc->host, mmc->tcp.port, mmc->udp.port, message, response);
|
||||
}
|
||||
|
||||
return MMC_REQUEST_DONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -805,6 +805,7 @@ mmc_pool_t *mmc_pool_new(TSRMLS_D) /* {{{ */
|
||||
}
|
||||
|
||||
mmc_pool_init_hash(pool TSRMLS_CC);
|
||||
pool->compress_threshold = MEMCACHE_G(compress_threshold);
|
||||
pool->min_compress_savings = MMC_DEFAULT_SAVINGS;
|
||||
|
||||
pool->sending = &(pool->_sending1);
|
||||
@@ -1459,6 +1460,20 @@ void mmc_pool_select(mmc_pool_t *pool, long timeout TSRMLS_DC) /*
|
||||
break;
|
||||
|
||||
case MMC_REQUEST_DONE:
|
||||
/* might have completed without having sent all data (e.g. object too large errors) */
|
||||
if (mmc->sendreq == mmc->readreq) {
|
||||
/* disconnect stream since data may have been sent before we received the SERVER_ERROR */
|
||||
mmc_server_disconnect(mmc, mmc->readreq->io TSRMLS_CC);
|
||||
|
||||
/* shift next request into send slot */
|
||||
mmc_pool_slot_send(pool, mmc, mmc_queue_pop(&(mmc->sendqueue)), 1 TSRMLS_CC);
|
||||
|
||||
/* clear out connection from send queue if no new request was slotted */
|
||||
if (!mmc->sendreq) {
|
||||
mmc_queue_remove(pool->sending, mmc);
|
||||
}
|
||||
}
|
||||
|
||||
/* release completed request */
|
||||
mmc_pool_release(pool, mmc->readreq);
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#define MMC_VALUE_HEADER "VALUE %250s %u %lu %lu" /* keep in sync with MMC_MAX_KEY_LEN */
|
||||
|
||||
#define MMC_COMPRESSION_LEVEL Z_DEFAULT_COMPRESSION
|
||||
#define MMC_DEFAULT_COMPRESS 20000 /* minimum 20k byte values for auto compression to be used */
|
||||
#define MMC_DEFAULT_SAVINGS 0.2 /* minimum 20% savings for compression to be used */
|
||||
|
||||
#define MMC_PROTO_TCP 0
|
||||
@@ -107,9 +108,9 @@ typedef char *(*mmc_stream_readline)(mmc_stream_t *stream, char *buf, size_t max
|
||||
struct mmc_stream {
|
||||
php_stream *stream;
|
||||
int fd; /* file descriptor for select() */
|
||||
unsigned short port;
|
||||
unsigned short port; /* tcp/udp port stream is connected to */
|
||||
int chunk_size; /* stream chunk size */
|
||||
int status;
|
||||
int status; /* stream status in MMC_STATUS_* status codes */
|
||||
long failed; /* the timestamp the stream was marked as failed */
|
||||
long retry_interval; /* seconds to wait before automatic reconnect */
|
||||
mmc_buffer_t buffer; /* read buffer (when using udp) */
|
||||
@@ -348,6 +349,7 @@ ZEND_BEGIN_MODULE_GLOBALS(memcache)
|
||||
long max_failover_attempts;
|
||||
long redundancy;
|
||||
long session_redundancy;
|
||||
long compress_threshold;
|
||||
ZEND_END_MODULE_GLOBALS(memcache)
|
||||
|
||||
#ifdef ZTS
|
||||
|
||||
@@ -36,9 +36,13 @@ http://pear.php.net/dtd/package-2.0.xsd">
|
||||
</stability>
|
||||
<license uri="http://www.php.net/license">PHP License</license>
|
||||
<notes>
|
||||
- Enabled compression by default for values larger than 20kb
|
||||
- Fixed PECL bug #14157 (Segmentation fault with errorcallback handler)
|
||||
- Fixed PECL bug #15342 (memcache keys whitespaces replace issue)
|
||||
- Fixed PECL request #14801 (Session handler and large sessions)
|
||||
- Added REPORT_ERRORS to php stream open
|
||||
- New INI directive
|
||||
memcache.compress_threshold = 20000
|
||||
</notes>
|
||||
<contents>
|
||||
<dir name="/">
|
||||
|
||||
@@ -17,7 +17,7 @@ var_dump($result);
|
||||
// Should generate a "SERVER_ERROR: out of memory"
|
||||
$var = str_repeat('a', 1500000);
|
||||
$memcache->setCompressThreshold(0);
|
||||
$result = $memcache->set('test_key', $var, false, 10);
|
||||
$result = @$memcache->set('test_key', $var, false, 10);
|
||||
var_dump($result);
|
||||
|
||||
echo "Done\n";
|
||||
|
||||
@@ -11,7 +11,7 @@ $var = 'test';
|
||||
error_reporting(E_ALL);
|
||||
|
||||
$result1 = memcache_set($memcache, 'non_existing_test_key', $var, false, 1);
|
||||
$result2 = memcache_add($memcache, 'non_existing_test_key', $var, false, 1);
|
||||
$result2 = @memcache_add($memcache, 'non_existing_test_key', $var, false, 1);
|
||||
|
||||
var_dump($result1);
|
||||
var_dump($result2);
|
||||
|
||||
@@ -11,6 +11,7 @@ $session_save_path = "tcp://$host:$port?persistent=1&udp_port=0&weight=2&timeout
|
||||
ini_set('session.save_handler', 'memcache');
|
||||
ini_set('session.save_path', $session_save_path);
|
||||
|
||||
|
||||
$result1 = session_start();
|
||||
$id = session_id();
|
||||
|
||||
@@ -25,6 +26,21 @@ $result4 = session_start();
|
||||
$result5 = session_destroy();
|
||||
$result6 = $memcache->get($id);
|
||||
|
||||
// Test large session
|
||||
$session_save_path = "tcp://$host:$port";
|
||||
ini_set('session.save_path', $session_save_path);
|
||||
|
||||
session_start();
|
||||
$largeval = str_repeat('a', 1024*2048);
|
||||
$_SESSION['_test_key']= $largeval;
|
||||
session_write_close();
|
||||
|
||||
ini_set('memcache.compress_threshold', 0);
|
||||
session_start();
|
||||
$largeval = str_repeat('a', 1024*2048);
|
||||
$_SESSION['_test_key']= $largeval;
|
||||
session_write_close();
|
||||
|
||||
var_dump($result1);
|
||||
var_dump($id);
|
||||
var_dump($result2);
|
||||
@@ -35,6 +51,10 @@ var_dump($result6);
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
%s: SERVER_ERROR object too large for cache
|
||||
(3) in %s
|
||||
|
||||
Warning: session_write_close(): Failed to write session data (memcache). %s
|
||||
bool(true)
|
||||
string(%d) "%s"
|
||||
bool(false)
|
||||
|
||||
Reference in New Issue
Block a user