cvs: pecl /memcache memcache.c /memcache/tests 100.phpt

From: Date: Mon, 16 Oct 2006 17:31:29 +0000
Subject: cvs: pecl /memcache memcache.c /memcache/tests 100.phpt
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-6492@lists.php.net to get a copy of this message
mikl Mon Oct 16 17:31:29 2006 UTC Modified files: /pecl/memcache memcache.c /pecl/memcache/tests 100.phpt Log: Added support for flush_all timestamp parameter http://cvs.php.net/viewvc.cgi/pecl/memcache/memcache.c?r1=1.64&r2=1.65&diff_format=u Index: pecl/memcache/memcache.c diff -u pecl/memcache/memcache.c:1.64 pecl/memcache/memcache.c:1.65 --- pecl/memcache/memcache.c:1.64 Sun Oct 15 18:29:10 2006 +++ pecl/memcache/memcache.c Mon Oct 16 17:31:28 2006 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: memcache.c,v 1.64 2006/10/15 18:29:10 mikl Exp $ */ +/* $Id: memcache.c,v 1.65 2006/10/16 17:31:28 mikl Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -213,7 +213,7 @@ static int mmc_exec_retrieval_cmd_multi(mmc_pool_t *, zval *, zval ** TSRMLS_DC); static int mmc_read_value(mmc_t *, char **, int *, zval ** TSRMLS_DC); static int mmc_delete(mmc_t *, char *, int, int TSRMLS_DC); -static int mmc_flush(mmc_t * TSRMLS_DC); +static int mmc_flush(mmc_t *, int TSRMLS_DC); static void php_mmc_store(INTERNAL_FUNCTION_PARAMETERS, char *, int); static int mmc_get_stats(mmc_t *, char *, int, int, zval * TSRMLS_DC); static int mmc_incr_decr(mmc_t *, int, char *, int, int, long * TSRMLS_DC); @@ -284,7 +284,7 @@ php_info_print_table_start(); php_info_print_table_header(2, "memcache support", "enabled"); php_info_print_table_row(2, "Active persistent connections", buf); - php_info_print_table_row(2, "Revision", "$Revision: 1.64 $"); + php_info_print_table_row(2, "Revision", "$Revision: 1.65 $"); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -569,7 +569,7 @@ } if (mmc->persistent) { - spprintf(&hash_key, "mmc_open___%s", hostname); + spprintf(&hash_key, 0, "memcache:%s", hostname); } #if PHP_API_VERSION > 20020918 @@ -660,7 +660,7 @@ * TODO: use client callback on successful reconnect to allow user to specify behaviour */ if (mmc->retry_interval >= 0 && (long)time(NULL) >= mmc->failed + mmc->retry_interval) { - if (_mmc_open(mmc, error_string, errnum TSRMLS_CC) /*&& mmc_flush(mmc TSRMLS_CC) > 0*/) { + if (_mmc_open(mmc, error_string, errnum TSRMLS_CC) /*&& mmc_flush(mmc, 0 TSRMLS_CC) > 0*/) { return 1; } mmc_server_deactivate(mmc TSRMLS_CC); @@ -1225,15 +1225,25 @@ } /* }}} */ -static int mmc_flush(mmc_t *mmc TSRMLS_DC) /* {{{ */ +static int mmc_flush(mmc_t *mmc, int timestamp TSRMLS_DC) /* {{{ */ { - int response_len; + char *command; + int command_len, response_len; MMC_DEBUG(("mmc_flush: flushing the cache")); - if (mmc_sendcmd(mmc, "flush_all", sizeof("flush_all") - 1 TSRMLS_CC) < 0) { + if (timestamp) { + command_len = spprintf(&command, 0, "flush_all %d", timestamp); + } + else { + command_len = spprintf(&command, 0, "flush_all"); + } + + if (mmc_sendcmd(mmc, command, command_len TSRMLS_CC) < 0) { + efree(command); return -1; } + efree(command); /* get server's response */ if ((response_len = mmc_readline(mmc TSRMLS_CC)) < 0){ @@ -2303,16 +2313,22 @@ } /* }}} */ -/* {{{ proto bool memcache_flush( object memcache ) - Flushes cache */ +/* {{{ proto bool memcache_flush( object memcache [, int timestamp ] ) + Flushes cache, optionally at the specified time */ PHP_FUNCTION(memcache_flush) { mmc_pool_t *pool; int i, failures = 0; zval *mmc_object = getThis(); + long timestamp = 0; if (mmc_object == NULL) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &mmc_object, memcache_class_entry_ptr) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &mmc_object, memcache_class_entry_ptr, &timestamp) == FAILURE) { + return; + } + } + else { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timestamp) == FAILURE) { return; } } @@ -2322,7 +2338,7 @@ } for (i=0; i<pool->num_servers; i++) { - if (!mmc_open(pool->servers[i], 1, NULL, NULL TSRMLS_CC) || mmc_flush(pool->servers[i] TSRMLS_CC) < 0) { + if (!mmc_open(pool->servers[i], 1, NULL, NULL TSRMLS_CC) || mmc_flush(pool->servers[i], timestamp TSRMLS_CC) < 0) { if (mmc_server_failure(pool->servers[i] TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_NOTICE, "marked server '%s:%d' as failed", pool->servers[i]->host, pool->servers[i]->port); } http://cvs.php.net/viewvc.cgi/pecl/memcache/tests/100.phpt?r1=1.2&r2=1.3&diff_format=u Index: pecl/memcache/tests/100.phpt diff -u pecl/memcache/tests/100.phpt:1.2 pecl/memcache/tests/100.phpt:1.3 --- pecl/memcache/tests/100.phpt:1.2 Wed May 17 21:15:18 2006 +++ pecl/memcache/tests/100.phpt Mon Oct 16 17:31:28 2006 @@ -11,18 +11,49 @@ include 'connect.inc'; -$memcache->addServer($nonExistingHost, $nonExistingPort); +// Test flush in future +$memcache = new Memcache(); +$memcache->addServer($host, $port); -$result1 = @$memcache->flush(); +$result1 = $memcache->set('test_key', 'abc'); +$result2 = $memcache->get('test_key'); var_dump($result1); +var_dump($result2); -$memcache2 = new Memcache(); -$memcache2->addServer($nonExistingHost, $nonExistingPort); +$result = $memcache->flush(time()+3); +var_dump($result); -$result2 = @$memcache2->flush(); -var_dump($result2); +sleep(2); + +$result = $memcache->get('test_key'); +var_dump($result); + +sleep(2); + +$result = $memcache->get('test_key'); +var_dump($result); + +// Test partly failing flush +$memcache = new Memcache(); +$memcache->addServer($host, $port); +$memcache->addServer($nonExistingHost, $nonExistingPort); + +$result = @$memcache->flush(); +var_dump($result); + +// Test failing flush +$memcache = new Memcache(); +$memcache->addServer($nonExistingHost, $nonExistingPort); + +$result = @$memcache->flush(); +var_dump($result); ?> --EXPECT-- bool(true) +string(3) "abc" +bool(true) +string(3) "abc" +bool(false) +bool(true) bool(false)

« previous php.pecl.cvs (#6492) next »