Skip to content

Commit ae7545e

Browse files
author
Mikko Koppanen
committed
Update license to 3.01. Moved session handler support to separate files. clean up unused variables
1 parent e1f8434 commit ae7545e

6 files changed

+260
-210
lines changed

Diff for: LICENSE

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--------------------------------------------------------------------
2-
The PHP License, Version 3.0
3-
Copyright (c) 1999 - 2003 The PHP Group. All rights reserved.
2+
The PHP License, version 3.01
3+
Copyright (c) 1999 - 2010 The PHP Group. All rights reserved.
44
--------------------------------------------------------------------
55

66
Redistribution and use in source and binary forms, with or without
@@ -38,8 +38,8 @@ are met:
3838

3939
6. Redistributions of any form whatsoever must retain the following
4040
acknowledgment:
41-
"This product includes PHP, freely available from
42-
<http://www.php.net/>".
41+
"This product includes PHP software, freely available from
42+
<http://www.php.net/software/>".
4343

4444
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
4545
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
@@ -64,5 +64,5 @@ The PHP Group can be contacted via Email at [email protected].
6464
For more information on the PHP Group and the PHP project,
6565
please see <http://www.php.net>.
6666

67-
This product includes the Zend Engine, freely available at
67+
PHP includes the Zend Engine, freely available at
6868
<http://www.zend.com>.

Diff for: config.m4

+7-1
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,14 @@ if test "$PHP_MEMCACHED" != "no"; then
240240
PHP_ADD_LIBRARY_WITH_PATH(memcached, $PHP_LIBMEMCACHED_DIR/$PHP_LIBDIR, MEMCACHED_SHARED_LIBADD)
241241

242242
PHP_SUBST(MEMCACHED_SHARED_LIBADD)
243+
244+
PHP_MEMCACHED_FILES="php_memcached.c fastlz/fastlz.c"
245+
246+
if test "$PHP_MEMCACHED_SESSION" != "no"; then
247+
PHP_MEMCACHED_FILES="${PHP_MEMCACHED_FILES} php_memcached_session.c"
248+
fi
243249

244-
PHP_NEW_EXTENSION(memcached, php_memcached.c fastlz/fastlz.c, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES)
250+
PHP_NEW_EXTENSION(memcached, $PHP_MEMCACHED_FILES, $ext_shared,,$SESSION_INCLUDES $IGBINARY_INCLUDES)
245251
PHP_ADD_BUILD_DIR($ext_builddir/fastlz, 1)
246252

247253
ifdef([PHP_ADD_EXTENSION_DEP],

Diff for: php_memcached.c

+7-195
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
+----------------------------------------------------------------------+
3-
| Copyright (c) 2009 The PHP Group |
3+
| Copyright (c) 2009-2010 The PHP Group |
44
+----------------------------------------------------------------------+
5-
| This source file is subject to version 3.0 of the PHP license, |
5+
| This source file is subject to version 3.01 of the PHP license, |
66
| that is bundled with this package in the file LICENSE, and is |
77
| available through the world-wide-web at the following url: |
8-
| http://www.php.net/license/3_0.txt. |
8+
| http://www.php.net/license/3_01.txt. |
99
| If you did not receive a copy of the PHP license and are unable to |
1010
| obtain it through the world-wide-web, please send a note to |
1111
| [email protected] so we can mail you a copy immediately. |
@@ -46,6 +46,10 @@
4646

4747
#include "php_memcached.h"
4848

49+
#ifdef HAVE_MEMCACHED_SESSION
50+
# include "php_memcached_session.h"
51+
#endif
52+
4953
#include "fastlz/fastlz.h"
5054
#include <zlib.h>
5155

@@ -356,7 +360,6 @@ static PHP_METHOD(Memcached, __construct)
356360

357361
zend_fcall_info fci;
358362
zend_fcall_info_cache fci_cache;
359-
zend_bool invoke_callback = 0;
360363

361364
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!f", &persistent_id,
362365
&persistent_id_len, &fci, &fci_cache) == FAILURE) {
@@ -689,7 +692,6 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
689692
for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(keys));
690693
zend_hash_get_current_data(Z_ARRVAL_P(keys), (void**)&entry) == SUCCESS;
691694
zend_hash_move_forward(Z_ARRVAL_P(keys))) {
692-
zval copy, *copy_ptr;
693695

694696
if (Z_TYPE_PP(entry) != IS_STRING) {
695697
convert_to_string_ex(entry);
@@ -1819,7 +1821,6 @@ PHP_METHOD(Memcached, getServerByKey)
18191821
PHP_METHOD(Memcached, getStats)
18201822
{
18211823
memcached_stat_st *stats;
1822-
memcached_server_st *servers;
18231824
memcached_return status;
18241825
zval *entry;
18251826
struct callbackContext context = {0};
@@ -1858,7 +1859,6 @@ PHP_METHOD(Memcached, getStats)
18581859
Returns the version of each memcached server in the pool */
18591860
PHP_METHOD(Memcached, getVersion)
18601861
{
1861-
memcached_server_st *servers;
18621862
memcached_return status = MEMCACHED_SUCCESS;
18631863
struct callbackContext context = {0};
18641864
memcached_server_function callbacks[1];
@@ -2916,194 +2916,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
29162916

29172917
/* }}} */
29182918

2919-
/* {{{ session support */
2920-
#if HAVE_MEMCACHED_SESSION
2921-
2922-
#define MEMC_SESS_DEFAULT_LOCK_WAIT 150000
2923-
#define MEMC_SESS_LOCK_EXPIRATION 30
2924-
2925-
ps_module ps_mod_memcached = {
2926-
PS_MOD(memcached)
2927-
};
2928-
2929-
static int php_memc_sess_lock(memcached_st *memc, const char *key TSRMLS_DC)
2930-
{
2931-
char *lock_key = NULL;
2932-
int lock_key_len = 0;
2933-
long attempts;
2934-
long lock_maxwait;
2935-
long lock_wait = MEMC_G(sess_lock_wait);
2936-
time_t expiration;
2937-
memcached_return status;
2938-
/* set max timeout for session_start = max_execution_time. (c) Andrei Darashenka, Richter & Poweleit GmbH */
2939-
2940-
lock_maxwait = zend_ini_long(ZEND_STRS("max_execution_time"), 0);
2941-
if (lock_maxwait <= 0) {
2942-
lock_maxwait = MEMC_SESS_LOCK_EXPIRATION;
2943-
}
2944-
if (lock_wait == 0) {
2945-
lock_wait = MEMC_SESS_DEFAULT_LOCK_WAIT;
2946-
}
2947-
expiration = time(NULL) + lock_maxwait + 1;
2948-
attempts = lock_maxwait * 1000000 / lock_wait;
2949-
2950-
lock_key_len = spprintf(&lock_key, 0, "lock.%s", key);
2951-
do {
2952-
status = memcached_add(memc, lock_key, lock_key_len, "1", sizeof("1")-1, expiration, 0);
2953-
if (status == MEMCACHED_SUCCESS) {
2954-
MEMC_G(sess_locked) = 1;
2955-
MEMC_G(sess_lock_key) = lock_key;
2956-
MEMC_G(sess_lock_key_len) = lock_key_len;
2957-
return 0;
2958-
}
2959-
2960-
if (lock_wait > 0) {
2961-
usleep(lock_wait);
2962-
}
2963-
} while(--attempts > 0);
2964-
2965-
efree(lock_key);
2966-
return -1;
2967-
}
2968-
2969-
static void php_memc_sess_unlock(memcached_st *memc TSRMLS_DC)
2970-
{
2971-
if (MEMC_G(sess_locked)) {
2972-
memcached_delete(memc, MEMC_G(sess_lock_key), MEMC_G(sess_lock_key_len), 0);
2973-
MEMC_G(sess_locked) = 0;
2974-
efree(MEMC_G(sess_lock_key));
2975-
MEMC_G(sess_lock_key_len) = 0;
2976-
}
2977-
}
2978-
2979-
PS_OPEN_FUNC(memcached)
2980-
{
2981-
memcached_st *memc_sess = PS_GET_MOD_DATA();
2982-
memcached_server_st *servers;
2983-
memcached_return status;
2984-
2985-
servers = memcached_servers_parse((char *)save_path);
2986-
if (servers) {
2987-
memc_sess = memcached_create(NULL);
2988-
if (memc_sess) {
2989-
status = memcached_server_push(memc_sess, servers);
2990-
memcached_server_list_free(servers);
2991-
2992-
if (memcached_callback_set(memc_sess, MEMCACHED_CALLBACK_PREFIX_KEY, MEMC_G(sess_prefix)) !=
2993-
MEMCACHED_SUCCESS) {
2994-
PS_SET_MOD_DATA(NULL);
2995-
memcached_free(memc_sess);
2996-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "bad memcached key prefix in memcached.sess_prefix");
2997-
return FAILURE;
2998-
}
2999-
3000-
if (status == MEMCACHED_SUCCESS) {
3001-
PS_SET_MOD_DATA(memc_sess);
3002-
return SUCCESS;
3003-
}
3004-
} else {
3005-
memcached_server_list_free(servers);
3006-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not allocate libmemcached structure");
3007-
}
3008-
} else {
3009-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to parse session.save_path");
3010-
}
3011-
3012-
PS_SET_MOD_DATA(NULL);
3013-
return FAILURE;
3014-
}
3015-
3016-
PS_CLOSE_FUNC(memcached)
3017-
{
3018-
memcached_st *memc_sess = PS_GET_MOD_DATA();
3019-
3020-
if (MEMC_G(sess_locking_enabled)) {
3021-
php_memc_sess_unlock(memc_sess TSRMLS_CC);
3022-
}
3023-
if (memc_sess) {
3024-
memcached_free(memc_sess);
3025-
PS_SET_MOD_DATA(NULL);
3026-
}
3027-
3028-
return SUCCESS;
3029-
}
3030-
3031-
PS_READ_FUNC(memcached)
3032-
{
3033-
char *payload = NULL;
3034-
size_t payload_len = 0;
3035-
char *sess_key = NULL;
3036-
int sess_key_len = 0;
3037-
uint32_t flags = 0;
3038-
memcached_return status;
3039-
memcached_st *memc_sess = PS_GET_MOD_DATA();
3040-
3041-
if (MEMC_G(sess_locking_enabled)) {
3042-
if (php_memc_sess_lock(memc_sess, key TSRMLS_CC) < 0) {
3043-
return FAILURE;
3044-
}
3045-
}
3046-
3047-
sess_key_len = spprintf(&sess_key, 0, "%s", key);
3048-
payload = memcached_get(memc_sess, sess_key, sess_key_len, &payload_len, &flags, &status);
3049-
efree(sess_key);
3050-
3051-
if (status == MEMCACHED_SUCCESS) {
3052-
*val = estrndup(payload, payload_len);
3053-
*vallen = payload_len;
3054-
free(payload);
3055-
return SUCCESS;
3056-
} else {
3057-
return FAILURE;
3058-
}
3059-
}
3060-
3061-
PS_WRITE_FUNC(memcached)
3062-
{
3063-
char *sess_key = NULL;
3064-
int sess_key_len = 0;
3065-
time_t expiration = 0;
3066-
memcached_return status;
3067-
memcached_st *memc_sess = PS_GET_MOD_DATA();
3068-
3069-
sess_key_len = spprintf(&sess_key, 0, "%s", key);
3070-
if (PS(gc_maxlifetime) > 0) {
3071-
expiration = PS(gc_maxlifetime);
3072-
}
3073-
status = memcached_set(memc_sess, sess_key, sess_key_len, val, vallen, expiration, 0);
3074-
efree(sess_key);
3075-
3076-
if (status == MEMCACHED_SUCCESS) {
3077-
return SUCCESS;
3078-
} else {
3079-
return FAILURE;
3080-
}
3081-
}
3082-
3083-
PS_DESTROY_FUNC(memcached)
3084-
{
3085-
char *sess_key = NULL;
3086-
int sess_key_len = 0;
3087-
memcached_st *memc_sess = PS_GET_MOD_DATA();
3088-
3089-
sess_key_len = spprintf(&sess_key, 0, "%s", key);
3090-
memcached_delete(memc_sess, sess_key, sess_key_len, 0);
3091-
efree(sess_key);
3092-
if (MEMC_G(sess_locking_enabled)) {
3093-
php_memc_sess_unlock(memc_sess TSRMLS_CC);
3094-
}
3095-
3096-
return SUCCESS;
3097-
}
3098-
3099-
PS_GC_FUNC(memcached)
3100-
{
3101-
return SUCCESS;
3102-
}
3103-
3104-
#endif
3105-
/* }}} */
3106-
31072919
/* {{{ methods arginfo */
31082920
ZEND_BEGIN_ARG_INFO_EX(arginfo___construct, 0, 0, 0)
31092921
ZEND_ARG_INFO(0, persistent_id)

Diff for: php_memcached.h

-9
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ PHP_MINFO_FUNCTION(memcached);
8686
#define MEMC_G(v) (php_memcached_globals.v)
8787
#endif
8888

89-
/* session handler struct */
90-
#if HAVE_MEMCACHED_SESSION
91-
#include "ext/session/php_session.h"
92-
93-
extern ps_module ps_mod_memcached;
94-
#define ps_memcached_ptr &ps_mod_memcached
95-
96-
PS_FUNCS(memcached);
97-
#endif
9889
#endif /* PHP_MEMCACHED_H */
9990

10091

0 commit comments

Comments
 (0)