|
1 | 1 | /*
|
2 | 2 | +----------------------------------------------------------------------+
|
3 |
| - | Copyright (c) 2009 The PHP Group | |
| 3 | + | Copyright (c) 2009-2010 The PHP Group | |
4 | 4 | +----------------------------------------------------------------------+
|
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, | |
6 | 6 | | that is bundled with this package in the file LICENSE, and is |
|
7 | 7 | | 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. | |
9 | 9 | | If you did not receive a copy of the PHP license and are unable to |
|
10 | 10 | | obtain it through the world-wide-web, please send a note to |
|
11 | 11 | | [email protected] so we can mail you a copy immediately. |
|
|
46 | 46 |
|
47 | 47 | #include "php_memcached.h"
|
48 | 48 |
|
| 49 | +#ifdef HAVE_MEMCACHED_SESSION |
| 50 | +# include "php_memcached_session.h" |
| 51 | +#endif |
| 52 | + |
49 | 53 | #include "fastlz/fastlz.h"
|
50 | 54 | #include <zlib.h>
|
51 | 55 |
|
@@ -356,7 +360,6 @@ static PHP_METHOD(Memcached, __construct)
|
356 | 360 |
|
357 | 361 | zend_fcall_info fci;
|
358 | 362 | zend_fcall_info_cache fci_cache;
|
359 |
| - zend_bool invoke_callback = 0; |
360 | 363 |
|
361 | 364 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!f", &persistent_id,
|
362 | 365 | &persistent_id_len, &fci, &fci_cache) == FAILURE) {
|
@@ -689,7 +692,6 @@ static void php_memc_getMulti_impl(INTERNAL_FUNCTION_PARAMETERS, zend_bool by_ke
|
689 | 692 | for (zend_hash_internal_pointer_reset(Z_ARRVAL_P(keys));
|
690 | 693 | zend_hash_get_current_data(Z_ARRVAL_P(keys), (void**)&entry) == SUCCESS;
|
691 | 694 | zend_hash_move_forward(Z_ARRVAL_P(keys))) {
|
692 |
| - zval copy, *copy_ptr; |
693 | 695 |
|
694 | 696 | if (Z_TYPE_PP(entry) != IS_STRING) {
|
695 | 697 | convert_to_string_ex(entry);
|
@@ -1819,7 +1821,6 @@ PHP_METHOD(Memcached, getServerByKey)
|
1819 | 1821 | PHP_METHOD(Memcached, getStats)
|
1820 | 1822 | {
|
1821 | 1823 | memcached_stat_st *stats;
|
1822 |
| - memcached_server_st *servers; |
1823 | 1824 | memcached_return status;
|
1824 | 1825 | zval *entry;
|
1825 | 1826 | struct callbackContext context = {0};
|
@@ -1858,7 +1859,6 @@ PHP_METHOD(Memcached, getStats)
|
1858 | 1859 | Returns the version of each memcached server in the pool */
|
1859 | 1860 | PHP_METHOD(Memcached, getVersion)
|
1860 | 1861 | {
|
1861 |
| - memcached_server_st *servers; |
1862 | 1862 | memcached_return status = MEMCACHED_SUCCESS;
|
1863 | 1863 | struct callbackContext context = {0};
|
1864 | 1864 | memcached_server_function callbacks[1];
|
@@ -2916,194 +2916,6 @@ static int php_memc_do_result_callback(zval *zmemc_obj, zend_fcall_info *fci,
|
2916 | 2916 |
|
2917 | 2917 | /* }}} */
|
2918 | 2918 |
|
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 |
| - |
3107 | 2919 | /* {{{ methods arginfo */
|
3108 | 2920 | ZEND_BEGIN_ARG_INFO_EX(arginfo___construct, 0, 0, 0)
|
3109 | 2921 | ZEND_ARG_INFO(0, persistent_id)
|
|
0 commit comments