Permalink
Browse files

Update license to 3.01. Moved session handler support to separate fil…

…es. clean up unused variables
  • Loading branch information...
1 parent e1f8434 commit ae7545e0b72344376c1b902a3c42d7357d6e8c64 Mikko Koppanen committed Nov 4, 2010
Showing with 260 additions and 210 deletions.
  1. +5 −5 LICENSE
  2. +7 −1 config.m4
  3. +7 −195 php_memcached.c
  4. +0 −9 php_memcached.h
  5. +203 −0 php_memcached_session.c
  6. +38 −0 php_memcached_session.h
View
10 LICENSE
@@ -1,6 +1,6 @@
--------------------------------------------------------------------
- The PHP License, Version 3.0
-Copyright (c) 1999 - 2003 The PHP Group. All rights reserved.
+ The PHP License, version 3.01
+Copyright (c) 1999 - 2010 The PHP Group. All rights reserved.
--------------------------------------------------------------------
Redistribution and use in source and binary forms, with or without
@@ -38,8 +38,8 @@ are met:
6. Redistributions of any form whatsoever must retain the following
acknowledgment:
- "This product includes PHP, freely available from
- <http://www.php.net/>".
+ "This product includes PHP software, freely available from
+ <http://www.php.net/software/>".
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
@@ -64,5 +64,5 @@ The PHP Group can be contacted via Email at group@php.net.
For more information on the PHP Group and the PHP project,
please see <http://www.php.net>.
-This product includes the Zend Engine, freely available at
+PHP includes the Zend Engine, freely available at
<http://www.zend.com>.
View
@@ -240,8 +240,14 @@ if test "$PHP_MEMCACHED" != "no"; then
PHP_ADD_LIBRARY_WITH_PATH(memcached, $PHP_LIBMEMCACHED_DIR/$PHP_LIBDIR, MEMCACHED_SHARED_LIBADD)
PHP_SUBST(MEMCACHED_SHARED_LIBADD)
+
+ PHP_MEMCACHED_FILES="php_memcached.c fastlz/fastlz.c"
+
+ if test "$PHP_MEMCACHED_SESSION" != "no"; then
+ PHP_MEMCACHED_FILES="${PHP_MEMCACHED_FILES} php_memcached_session.c"
+ fi
- PHP_NEW_EXTENSION(memcached, php_memcached.c fastlz/fastlz.c, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES)
+ PHP_NEW_EXTENSION(memcached, $PHP_MEMCACHED_FILES, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES)
PHP_ADD_BUILD_DIR($ext_builddir/fastlz, 1)
ifdef([PHP_ADD_EXTENSION_DEP],
View
@@ -1,11 +1,11 @@
/*
+----------------------------------------------------------------------+
- | Copyright (c) 2009 The PHP Group |
+ | Copyright (c) 2009-2010 The PHP Group |
+----------------------------------------------------------------------+
- | This source file is subject to version 3.0 of the PHP license, |
+ | This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
- | http://www.php.net/license/3_0.txt. |
+ | http://www.php.net/license/3_01.txt. |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
@@ -46,6 +46,10 @@
#include "php_memcached.h"
+#ifdef HAVE_MEMCACHED_SESSION
+# include "php_memcached_session.h"
+#endif
+
#include "fastlz/fastlz.h"
#include <zlib.h>
@@ -356,7 +360,6 @@ static PHP_METHOD(Memcached, __construct)
zend_fcall_info fci;
zend_fcall_info_cache fci_cache;
- zend_bool invoke_callback = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!f", &persistent_id,
&persistent_id_len, &fci, &fci_cache) == FAILURE) {
@@ -689,7 +692,6 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(keys));
zend_hash_get_current_data(Z_ARRVAL_P(keys), (void**)&entry) == SUCCESS;
zend_hash_move_forward(Z_ARRVAL_P(keys))) {
- zval copy, *copy_ptr;
if (Z_TYPE_PP(entry) != IS_STRING) {
convert_to_string_ex(entry);
@@ -1819,7 +1821,6 @@ PHP_METHOD(Memcached, getServerByKey)
PHP_METHOD(Memcached, getStats)
{
memcached_stat_st *stats;
- memcached_server_st *servers;
memcached_return status;
zval *entry;
struct callbackContext context = {0};
@@ -1858,7 +1859,6 @@ PHP_METHOD(Memcached, getStats)
Returns the version of each memcached server in the pool */
PHP_METHOD(Memcached, getVersion)
{
- memcached_server_st *servers;
memcached_return status = MEMCACHED_SUCCESS;
struct callbackContext context = {0};
memcached_server_function callbacks[1];
@@ -2916,194 +2916,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
/* }}} */
-/* {{{ session support */
-#if HAVE_MEMCACHED_SESSION
-
-#define MEMC_SESS_DEFAULT_LOCK_WAIT 150000
-#define MEMC_SESS_LOCK_EXPIRATION 30
-
-ps_module ps_mod_memcached = {
- PS_MOD(memcached)
-};
-
-static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC)
-{
- char *lock_key = NULL;
- int lock_key_len = 0;
- long attempts;
- long lock_maxwait;
- long lock_wait = MEMC_G(sess_lock_wait);
- time_t expiration;
- memcached_return status;
- /* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */
-
- lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
- if (lock_maxwait <= 0) {
- lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
- }
- if (lock_wait == 0) {
- lock_wait = MEMC_SESS_DEFAULT_LOCK_WAIT;
- }
- expiration = time(NULL) + lock_maxwait + 1;
- attempts = lock_maxwait * 1000000 / lock_wait;
-
- lock_key_len = spprintf(&lock_key, 0, "lock.%s", key);
- do {
- status = memcached_add(memc, lock_key, lock_key_len, "1", sizeof("1")-1, expiration, 0);
- if (status == MEMCACHED_SUCCESS) {
- MEMC_G(sess_locked) = 1;
- MEMC_G(sess_lock_key) = lock_key;
- MEMC_G(sess_lock_key_len) = lock_key_len;
- return 0;
- }
-
- if (lock_wait > 0) {
- usleep(lock_wait);
- }
- } while(--attempts > 0);
-
- efree(lock_key);
- return -1;
-}
-
-static void php_memc_sess_unlock(memcached_st *memc TSRMLS_DC)
-{
- if (MEMC_G(sess_locked)) {
- memcached_delete(memc, MEMC_G(sess_lock_key), MEMC_G(sess_lock_key_len), 0);
- MEMC_G(sess_locked) = 0;
- efree(MEMC_G(sess_lock_key));
- MEMC_G(sess_lock_key_len) = 0;
- }
-}
-
-PS_OPEN_FUNC(memcached)
-{
- memcached_st *memc_sess = PS_GET_MOD_DATA();
- memcached_server_st *servers;
- memcached_return status;
-
- servers = memcached_servers_parse((char *)save_path);
- if (servers) {
- memc_sess = memcached_create(NULL);
- if (memc_sess) {
- status = memcached_server_push(memc_sess, servers);
- memcached_server_list_free(servers);
-
- if (memcached_callback_set(memc_sess, MEMCACHED_CALLBACK_PREFIX_KEY, MEMC_G(sess_prefix)) !=
- MEMCACHED_SUCCESS) {
- PS_SET_MOD_DATA(NULL);
- memcached_free(memc_sess);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad memcached key prefix in memcached.sess_prefix");
- return FAILURE;
- }
-
- if (status == MEMCACHED_SUCCESS) {
- PS_SET_MOD_DATA(memc_sess);
- return SUCCESS;
- }
- } else {
- memcached_server_list_free(servers);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not allocate libmemcached structure");
- }
- } else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to parse session.save_path");
- }
-
- PS_SET_MOD_DATA(NULL);
- return FAILURE;
-}
-
-PS_CLOSE_FUNC(memcached)
-{
- memcached_st *memc_sess = PS_GET_MOD_DATA();
-
- if (MEMC_G(sess_locking_enabled)) {
- php_memc_sess_unlock(memc_sess TSRMLS_CC);
- }
- if (memc_sess) {
- memcached_free(memc_sess);
- PS_SET_MOD_DATA(NULL);
- }
-
- return SUCCESS;
-}
-
-PS_READ_FUNC(memcached)
-{
- char *payload = NULL;
- size_t payload_len = 0;
- char *sess_key = NULL;
- int sess_key_len = 0;
- uint32_t flags = 0;
- memcached_return status;
- memcached_st *memc_sess = PS_GET_MOD_DATA();
-
- if (MEMC_G(sess_locking_enabled)) {
- if (php_memc_sess_lock(memc_sess, key TSRMLS_CC) < 0) {
- return FAILURE;
- }
- }
-
- sess_key_len = spprintf(&sess_key, 0, "%s", key);
- payload = memcached_get(memc_sess, sess_key, sess_key_len, &payload_len, &flags, &status);
- efree(sess_key);
-
- if (status == MEMCACHED_SUCCESS) {
- *val = estrndup(payload, payload_len);
- *vallen = payload_len;
- free(payload);
- return SUCCESS;
- } else {
- return FAILURE;
- }
-}
-
-PS_WRITE_FUNC(memcached)
-{
- char *sess_key = NULL;
- int sess_key_len = 0;
- time_t expiration = 0;
- memcached_return status;
- memcached_st *memc_sess = PS_GET_MOD_DATA();
-
- sess_key_len = spprintf(&sess_key, 0, "%s", key);
- if (PS(gc_maxlifetime) > 0) {
- expiration = PS(gc_maxlifetime);
- }
- status = memcached_set(memc_sess, sess_key, sess_key_len, val, vallen, expiration, 0);
- efree(sess_key);
-
- if (status == MEMCACHED_SUCCESS) {
- return SUCCESS;
- } else {
- return FAILURE;
- }
-}
-
-PS_DESTROY_FUNC(memcached)
-{
- char *sess_key = NULL;
- int sess_key_len = 0;
- memcached_st *memc_sess = PS_GET_MOD_DATA();
-
- sess_key_len = spprintf(&sess_key, 0, "%s", key);
- memcached_delete(memc_sess, sess_key, sess_key_len, 0);
- efree(sess_key);
- if (MEMC_G(sess_locking_enabled)) {
- php_memc_sess_unlock(memc_sess TSRMLS_CC);
- }
-
- return SUCCESS;
-}
-
-PS_GC_FUNC(memcached)
-{
- return SUCCESS;
-}
-
-#endif
-/* }}} */
-
/* {{{ methods arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo___construct, 0, 0, 0)
ZEND_ARG_INFO(0, persistent_id)
View
@@ -86,15 +86,6 @@ PHP_MINFO_FUNCTION(memcached);
#define MEMC_G(v) (php_memcached_globals.v)
#endif
-/* session handler struct */
-#if HAVE_MEMCACHED_SESSION
-#include "ext/session/php_session.h"
-
-extern ps_module ps_mod_memcached;
-#define ps_memcached_ptr &ps_mod_memcached
-
-PS_FUNCS(memcached);
-#endif
#endif /* PHP_MEMCACHED_H */
Oops, something went wrong.

0 comments on commit ae7545e

Please sign in to comment.