Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pull from upstream

  • Loading branch information...
commit fb69c1a049b26c99a3c5b102db6d664820078262 2 parents fc7cd3e + 51ef6a6
@RJ authored
View
11 ChangeLog
@@ -0,0 +1,11 @@
+memcached extension changelog
+
+Version 0.1.1
+-------------
+ * Add OPT_LIBKETAMA_COMPATIBLE option.
+ * Implement addServers() method.
+ * Swap internal compressed and serialized flags to be compatible with other clients.
+
+Version 0.1.0
+-------------
+ * Initial release
View
7 README
@@ -1,9 +1,12 @@
-This is a PHP extension for interfacing with memcached via libmemcached library.
+This extension uses libmemcached library to provide API for communicating with
+memcached servers.
+memcached is a high-performance, distributed memory object caching system,
+generic in nature, but intended for use in speeding up dynamic web applications
+by alleviating database load.
Resources
---------
-
libmemcached:
http://tangent.org/552/libmemcached.html
View
25 manual/Makefile
@@ -1,25 +0,0 @@
-# test
-# line 2
-all: html
-
-confcheck:
- @if test "x$(PHPDOC)" = "x"; then echo PHPDOC not set; exit 3; fi
-
-manual.xml: manual.xml.in
- sed -e's:@PHPDOC@:$(PHPDOC):g' < manual.xml.in > manual.xml
-
-html: confcheck manual.xml
- rm -rf html; mkdir html
- SP_ENCODING=XML SP_CHARSET_FIXED=YES openjade -D $(PHPDOC) -wno-idref -c $(PHPDOC)/docbook/docbook-dsssl/catalog -c $(PHPDOC)/phpbook/phpbook-dsssl/defaults/catalog -d $(PHPDOC)/phpbook/phpbook-dsssl/html.dsl -V use-output-dir -t sgml $(PHPDOC)/phpbook/phpbook-xml/phpdocxml.dcl manual.xml
-
-bightml: confcheck manual.xml
- rm -rf html; mkdir html
- SP_ENCODING=XML SP_CHARSET_FIXED=YES openjade -D $(PHPDOC) -wno-idref -c $(PHPDOC)/docbook/docbook-dsssl/catalog -c $(PHPDOC)/phpbook/phpbook-dsssl/defaults/catalog -d $(PHPDOC)/phpbook/phpbook-dsssl/html.dsl -V nochunks -t sgml $(PHPDOC)/phpbook/phpbook-xml/phpdocxml.dcl manual.xml > manual.html
-
-tex: manual.tex
-
-manual.tex: confcheck manual.xml
- SP_ENCODING=XML SP_CHARSET_FIXED=YES openjade -D $(PHPDOC) -wno-idref -c $(PHPDOC)/docbook/docbook-dsssl/catalog -c $(PHPDOC)/phpbook/phpbook-dsssl/defaults/catalog -d $(PHPDOC)/phpbook/phpbook-dsssl/print.dsl -t tex $(PHPDOC)/phpbook/phpbook-xml/phpdocxml.dcl manual.xml
-
-pdf: manual.tex
- pdfjadetex manual.tex && pdfjadetex manual.tex && pdfjadetex manual.tex
View
3  manual/file-entities.ent
@@ -1,3 +0,0 @@
-<!ENTITY reference.memcached.reference SYSTEM './memcached/reference.xml'>
-<!ENTITY reference.memcached.configure SYSTEM './memcached/configure.xml'>
-<!ENTITY reference.memcached.functions SYSTEM './functions.xml'>
View
0  manual/functions.xml
No changes.
View
37 manual/manual.xml.in
@@ -1,37 +0,0 @@
-<?xml version='1.0' encoding='UTF-8' ?>
-<!DOCTYPE book PUBLIC '-//OASIS//DTD DocBook XML V4.1.2//EN'
- '@PHPDOC@/dtds/dbxml-4.1.2/docbookx.dtd' [
-
-<!-- Add translated specific definitions and snippets -->
-<!ENTITY % language-defs SYSTEM '@PHPDOC@/en/language-defs.ent'>
-<!ENTITY % language-snippets SYSTEM '@PHPDOC@/en/language-snippets.ent'>
-
-%language-defs;
-%language-snippets;
-
-<!-- Fallback to English definitions and snippets (in case of missing translation) -->
-<!ENTITY % language-defs.default SYSTEM '@PHPDOC@/en/language-defs.ent'>
-<!ENTITY % language-snippets.default SYSTEM '@PHPDOC@/en/language-snippets.ent'>
-<!ENTITY % extensions.default SYSTEM '@PHPDOC@/en/extensions.ent'>
-
-%language-defs.default;
-%language-snippets.default;
-%extensions.default;
-
-<!-- All global entities for the XML files -->
-<!ENTITY % global.entities SYSTEM '@PHPDOC@/entities/global.ent'>
-
-<!ENTITY % file.entities SYSTEM './file-entities.ent'>
-
-<!-- Include all external DTD parts defined previously -->
-%global.entities;
-%file.entities;
-
-<!-- Autogenerated missing entites and IDs to make build work -->
-<!ENTITY % missing-entities SYSTEM '@PHPDOC@/entities/missing-entities.ent'>
-%missing-entities;
-]>
-
-<book id='manual' lang='en'>
- &reference.memcached.reference;
-</book>
View
43 manual/memcached/configure.xml
@@ -1,43 +0,0 @@
-
- <section id='memcached.requirements'>
- &reftitle.required;
-<para>This extension requires the following library: memcached</para>
-<para>This extension requires the following header: libmemcached/memcached.h</para>
-
- </section>
-
-
- <section id='memcached.install'>
- &reftitle.install;
- <para>Requires <literal>memcached</literal></para>
-
- </section>
-
-
- <section id='memcached.configuration'>
- &reftitle.runtime;
- &no.config;
-
- </section>
-
-
-<!-- Keep this comment at the end of the file
-Local variables:
-mode: sgml
-sgml-omittag:t
-sgml-shorttag:t
-sgml-minimize-attributes:nil
-sgml-always-quote-attributes:t
-sgml-indent-step:1
-sgml-indent-data:t
-indent-tabs-mode:nil
-sgml-parent-document:nil
-sgml-default-dtd-file:"../../../manual.ced"
-sgml-exposed-tags:nil
-sgml-local-catalogs:nil
-sgml-local-ecat-files:nil
-End:
-vim600: syn=xml fen fdm=syntax fdl=2 si
-vim: et tw=78 syn=sgml
-vi: ts=1 sw=1
--->
View
53 manual/memcached/reference.xml
@@ -1,53 +0,0 @@
-<?xml version='1.0' encoding='iso-8859-1'?>
-<!-- $Revision: 1.1 $ -->
- <reference id='ref.memcached'>
- <title>libmemcached extension</title>
- <titleabbrev>memcached</titleabbrev>
-
- <partintro>
- <section id='memcached.intro'>
- &reftitle.intro;
- <para>
- Extension for interfacing with memcache servers via libmemcached library.
-
- </para>
- </section>
-
- &reference.memcached.configure;
-
- <section id='memcached.resources'>
- &reftitle.resources;
- &no.resource;
- </section>
-
- <section id='memcached.constants'>
- &reftitle.constants;
- &no.constants;
- </section>
-
- </partintro>
-
-&reference.memcached.functions;
-
- </reference>
-
-<!-- Keep this comment at the end of the file
-Local variables:
-mode: sgml
-sgml-omittag:t
-sgml-shorttag:t
-sgml-minimize-attributes:nil
-sgml-always-quote-attributes:t
-sgml-indent-step:1
-sgml-indent-data:t
-indent-tabs-mode:nil
-sgml-parent-document:nil
-sgml-default-dtd-file:"../../../manual.ced"
-sgml-exposed-tags:nil
-sgml-local-catalogs:nil
-sgml-local-ecat-files:nil
-End:
-vim600: syn=xml fen fdm=syntax fdl=2 si
-vim: et tw=78 syn=sgml
-vi: ts=1 sw=1
--->
View
8 memcached-api.php
@@ -36,7 +36,9 @@ class Memcached {
const OPT_DISTRIBUTION_CONSISTENT;
- const OPT_BUFER_REQUESTS;
+ const OPT_LIBKETAMA_COMPATIBLE;
+
+ const OPT_BUFFER_REQUESTS;
const OPT_BINARY_PROTOCOL;
@@ -129,7 +131,9 @@ public function getOption( $option ) {}
public function setOption( $option, $value ) {}
- public function addServer( $host, $port, $weight = 0 );
+ public function addServer( $host, $port, $weight = 0 ) {}
+
+ public function addServers( array $servers ) {}
public function getServerList( ) {}
View
23 package.xml
@@ -15,23 +15,28 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>andrei@php.net</email>
<active>yes</active>
</lead>
- <date>2009-01-29</date>
+ <date>2009-02-02</date>
<version>
- <release>0.1.0</release>
- <api>0.1.0</api>
+ <release>0.1.1</release>
+ <api>0.1.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www.php.net/license">PHP</license>
- <notes>Initial PECL release</notes>
+ <notes>
+- Add OPT_LIBKETAMA_COMPATIBLE option.
+- Implement addServers() method.
+- Swap internal compressed and serialized flags to be compatible with other clients.
+ </notes>
<contents>
<dir name="/">
<file role='doc' name='EXPERIMENTAL'/>
<file role='doc' name='README'/>
<file role='doc' name='CREDITS'/>
<file role='doc' name='LICENSE'/>
+ <file role='doc' name='ChangeLog'/>
<file role='doc' name='memcached-api.php'/>
<file role='src' name='config.m4'/>
<file role='src' name='config.w32'/>
@@ -56,6 +61,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
<changelog>
<release>
<stability><release>beta</release><api>beta</api></stability>
+ <version><release>0.1.1</release><api>0.1.1</api></version>
+ <date>2009-02-02</date>
+ <notes>
+- Add OPT_LIBKETAMA_COMPATIBLE option.
+- Implement addServers() method.
+- Swap internal compressed and serialized flags to be compatible with other clients.
+ </notes>
+ </release>
+ <release>
+ <stability><release>beta</release><api>beta</api></stability>
<version><release>0.1.0</release><api>0.1.0</api></version>
<date>2009-01-29</date>
<notes>
View
93 php_memcached.c
@@ -1302,6 +1302,71 @@ PHP_METHOD(Memcached, addServer)
}
/* }}} */
+/* {{{ Memcached::addServers(array servers)
+ Adds the given memcache servers to the server list */
+PHP_METHOD(Memcached, addServers)
+{
+ zval *servers;
+ zval **entry;
+ zval **z_host, **z_port, **z_weight = NULL;
+ uint32_t weight = 0;
+ int entry_size, i = 0;
+ memcached_server_st *list = NULL;
+ memcached_return status;
+ MEMC_METHOD_INIT_VARS;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &servers) == FAILURE) {
+ return;
+ }
+
+ MEMC_METHOD_FETCH_OBJECT;
+ MEMC_G(rescode) = MEMCACHED_SUCCESS;
+
+ for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(servers)), i = 0;
+ zend_hash_get_current_data(Z_ARRVAL_P(servers), (void **)&entry) == SUCCESS;
+ zend_hash_move_forward(Z_ARRVAL_P(servers)), i++) {
+
+ if (Z_TYPE_PP(entry) != IS_ARRAY) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "server list entry #%d is not an array", i+1);
+ continue;
+ }
+
+ entry_size = zend_hash_num_elements(Z_ARRVAL_PP(entry));
+
+ if (entry_size > 1) {
+ zend_hash_index_find(Z_ARRVAL_PP(entry), 0, (void **)&z_host);
+ zend_hash_index_find(Z_ARRVAL_PP(entry), 1, (void **)&z_port);
+ convert_to_string_ex(z_host);
+ convert_to_long_ex(z_port);
+
+ weight = 0;
+ if (entry_size > 2) {
+ zend_hash_index_find(Z_ARRVAL_PP(entry), 2, (void **)&z_weight);
+ convert_to_long_ex(z_weight);
+ weight = Z_LVAL_PP(z_weight);
+ }
+
+ list = memcached_server_list_append_with_weight(list, Z_STRVAL_PP(z_host),
+ Z_LVAL_PP(z_port), weight, &status);
+
+ if (php_memc_handle_error(status TSRMLS_CC) == 0) {
+ continue;
+ }
+ }
+
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not add entry #%d to the server list", i+1);
+ }
+
+ status = memcached_server_push(i_obj->memc, list);
+ memcached_server_list_free(list);
+ if (php_memc_handle_error(status TSRMLS_CC) < 0) {
+ RETURN_FALSE;
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
/* {{{ Memcached::getServerList()
Returns the list of the memcache servers in use */
PHP_METHOD(Memcached, getServerList)
@@ -1548,6 +1613,25 @@ static PHP_METHOD(Memcached, setOption)
break;
}
+ case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
+ flag = (memcached_behavior) option;
+ convert_to_long(value);
+ if (memcached_behavior_set(i_obj->memc, flag, (uint64_t)Z_LVAL_P(value)) == MEMCACHED_FAILURE) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "error setting memcached option");
+ RETURN_FALSE;
+ }
+
+ /*
+ * This is necessary because libmemcached does not reset hash/distribution
+ * options on false case, like it does for MEMCACHED_BEHAVIOR_KETAMA
+ * (non-weighted) case. We have to clean up ourselves.
+ */
+ if (!Z_LVAL_P(value)) {
+ i_obj->memc->hash = 0;
+ i_obj->memc->distribution = 0;
+ }
+ break;
+
default:
/*
* Assume that it's a libmemcached behavior option.
@@ -2344,6 +2428,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_addServer, 0, 0, 2)
ZEND_END_ARG_INFO()
static
+ZEND_BEGIN_ARG_INFO(arginfo_addServers, 0)
+ ZEND_ARG_ARRAY_INFO(0, servers, 0)
+ZEND_END_ARG_INFO()
+
+static
ZEND_BEGIN_ARG_INFO(arginfo_getServerList, 0)
ZEND_END_ARG_INFO()
@@ -2406,6 +2495,7 @@ static zend_function_entry memcached_class_methods[] = {
MEMC_ME(decrement, arginfo_decrement)
MEMC_ME(addServer, arginfo_addServer)
+ MEMC_ME(addServers, arginfo_addServers)
MEMC_ME(getServerList, arginfo_getServerList)
MEMC_ME(getServerByKey, arginfo_getServerByKey)
@@ -2483,7 +2573,7 @@ static void php_memc_register_constants(INIT_FUNC_ARGS)
REGISTER_MEMC_CLASS_CONST_LONG(OPT_DISTRIBUTION, MEMCACHED_BEHAVIOR_DISTRIBUTION);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_MODULA, MEMCACHED_DISTRIBUTION_MODULA);
REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_CONSISTENT, MEMCACHED_DISTRIBUTION_CONSISTENT);
- REGISTER_MEMC_CLASS_CONST_LONG(DISTRIBUTION_KETAMA_WEIGHTED, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
+ REGISTER_MEMC_CLASS_CONST_LONG(OPT_LIBKETAMA_COMPATIBLE, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_BUFFER_WRITES, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_BINARY_PROTOCOL, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL);
REGISTER_MEMC_CLASS_CONST_LONG(OPT_NO_BLOCK, MEMCACHED_BEHAVIOR_NO_BLOCK);
@@ -2587,7 +2677,6 @@ PHP_MINFO_FUNCTION(memcached)
php_info_print_table_start();
php_info_print_table_header(2, "memcached support", "enabled");
php_info_print_table_row(2, "Version", PHP_MEMCACHED_VERSION);
- php_info_print_table_row(2, "Revision", "$Revision: 1.1 $");
php_info_print_table_row(2, "libmemcached version", memcached_lib_version());
php_info_print_table_end();
}
View
2  php_memcached.h
@@ -49,7 +49,7 @@ PHP_RINIT_FUNCTION(memcached);
PHP_RSHUTDOWN_FUNCTION(memcached);
PHP_MINFO_FUNCTION(memcached);
-#define PHP_MEMCACHED_VERSION "0.1.0"
+#define PHP_MEMCACHED_VERSION "0.1.1"
#ifdef ZTS
#define MEMC_G(v) TSRMG(php_memcached_globals_id, zend_memcache_globals *, v)
Please sign in to comment.
Something went wrong with that request. Please try again.