Changeset 258

Show
Ignore:
Timestamp:
07/30/06 16:35:03 (2 years ago)
Author:
bart
Message:

Clean up the session handler, removed old code for php < 4.3.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • eaccelerator/trunk/ChangeLog

    r256 r258  
    99                * Remove some leftovers from restoring encoded scripts which only create 
    1010                  overhead without the loader. 
     11        * Clean up the session handler, removed old code for php < 4.3.  
    1112                   
    12132006-07-29  Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> 
  • eaccelerator/trunk/config.m4

    r246 r258  
    107107    AC_DEFINE(WITH_EACCELERATOR_INFO, 1, [Define if you want the information functions]) 
    108108  fi 
    109   if test "$eaccelerator_sessions" = "yes"; then 
    110     AC_DEFINE(WITH_EACCELERATOR_SESSIONS, 1, [Define if you like to use eAccelerator session handlers to store session's information in shared memory]) 
    111   fi 
    112109  if test "$eaccelerator_content_caching" = "yes"; then 
    113110    AC_DEFINE(WITH_EACCELERATOR_CONTENT_CACHING, 1, [Define if you like to use eAccelerator content cachin API]) 
     
    138135#include <sys/types.h>],msg=yes,msg=no) 
    139136  AC_MSG_RESULT([$msg]) 
     137 
     138  old_cppflags="$CPPFLAGS" 
     139  CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir" 
     140  AC_MSG_CHECKING(for ext/session/php_session.h) 
     141  AC_TRY_CPP([#include "ext/session/php_session.h"],msg="yes",msg="no") 
     142  if test "$msg" = "yes"; then 
     143    AC_DEFINE(HAVE_EXT_SESSION_PHP_SESSION_H, 1, [Define if you have the <ext/session/php_session.h> header file.]) 
     144  fi 
     145  AC_MSG_RESULT([$msg]) 
     146  CPPFLAGS="$old_cppflags" 
     147  if test "$msg" = "yes" && test "$eaccelerator_sessions" = "yes"; then 
     148    AC_DEFINE(WITH_EACCELERATOR_SESSIONS, 1, [Define if you like to use eAccelerator session handlers to store session's information in shared memory]) 
     149  elif test "$eaccelerator_sessions" = "yes"; then 
     150    AC_MSG_ERROR("Can't compile eAccelerator with session support if php isn't compiled with session support!") 
     151  fi 
     152 
    140153 
    141154  AC_MSG_CHECKING(whether union semun is defined in sys/sem.h) 
     
    326339      AC_DEFINE(HAVE_MPROTECT, 1, [Define if ou have mprotect function]) 
    327340    ]) 
    328  
    329   old_cppflags="$CPPFLAGS" 
    330   CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir" 
    331   AC_MSG_CHECKING(for ext/session/php_session.h) 
    332   AC_TRY_CPP([#include "ext/session/php_session.h"],msg="yes",msg="no") 
    333   if test "$msg" = "yes"; then 
    334     AC_DEFINE(HAVE_EXT_SESSION_PHP_SESSION_H, 1, [Define if you have the <ext/session/php_session.h> header file.]) 
    335   fi 
    336   AC_MSG_RESULT([$msg]) 
    337   CPPFLAGS="$old_cppflags" 
    338  
    339341fi 
  • eaccelerator/trunk/eaccelerator.c

    r256 r258  
    17461746#endif 
    17471747  } 
    1748 #if defined(WITH_EACCELERATOR_SESSIONS) && defined(HAVE_PHP_SESSIONS_SUPPORT) 
    1749   if (!eaccelerator_session_registered()) { 
    1750     eaccelerator_register_session(); 
    1751   } 
     1748   
     1749#ifdef WITH_EACCELERATOR_SESSIONS 
     1750  eaccelerator_register_session(); 
    17521751#endif 
    17531752#ifdef WITH_EACCELERATOR_CONTENT_CACHING 
     
    17571756    register_eaccelerator_as_zend_extension(); 
    17581757  } 
     1758   
    17591759#ifdef ZEND_ENGINE_2 
    17601760  /* cache the properties_info destructor */ 
     
    19461946  PHP_FE(eaccelerator_removed_scripts, NULL) 
    19471947  PHP_FE(eaccelerator_list_keys, NULL) 
    1948 #endif 
    1949 #ifdef WITH_EACCELERATOR_SESSIONS 
    1950 #ifndef HAVE_PHP_SESSIONS_SUPPORT 
    1951   PHP_FE(_eaccelerator_session_open, NULL) 
    1952   PHP_FE(_eaccelerator_session_close, NULL) 
    1953   PHP_FE(_eaccelerator_session_read, NULL) 
    1954   PHP_FE(_eaccelerator_session_write, NULL) 
    1955   PHP_FE(_eaccelerator_session_destroy, NULL) 
    1956   PHP_FE(_eaccelerator_session_gc, NULL) 
    1957 #endif 
    1958   PHP_FE(eaccelerator_set_session_handlers, NULL) 
    19591948#endif 
    19601949#ifdef WITH_EACCELERATOR_CONTENT_CACHING 
  • eaccelerator/trunk/session.c

    r254 r258  
    3333#include "cache.h" 
    3434#include "ext/standard/md5.h" 
     35#include "ext/standard/php_lcg.h" 
    3536#include <fcntl.h> 
    3637 
    3738#ifdef WIN32 
    3839#       include "win32/time.h" 
    39 #endif 
    40  
    41 #if defined(HAVE_PHP_SESSIONS_SUPPORT) && defined(PS_CREATE_SID_ARGS) 
    42 #       include "ext/standard/php_lcg.h" 
    4340#endif 
    4441 
     
    9390} 
    9491 
    95 #ifdef HAVE_PHP_SESSIONS_SUPPORT        /* PHP_SESSION_API >= 20020306 */ 
    9692/******************************************************************************/ 
    9793/* Session api functions                                                                                                          */ 
    9894/******************************************************************************/ 
    99  
    10095PS_OPEN_FUNC(eaccelerator) 
    10196{ 
     
    199194} 
    200195 
    201 #ifdef PS_CREATE_SID_ARGS 
    202196PS_CREATE_SID_FUNC(eaccelerator) 
    203197{ 
     
    262256        return estrdup (buf); 
    263257} 
    264 #endif 
    265  
    266 #else 
    267 /******************************************************************************/ 
    268 /* PHP function to register as user session handlers when the session api         */ 
    269 /* available.                                                                                                                             */ 
    270 /******************************************************************************/ 
    271  
    272 PHP_FUNCTION(_eaccelerator_session_open) 
    273 { 
    274         if (eaccelerator_mm_instance == NULL) { 
    275                 RETURN_FALSE; 
    276         } 
    277         RETURN_TRUE; 
    278 } 
    279  
    280 PHP_FUNCTION(_eaccelerator_session_close) 
    281 { 
    282         if (eaccelerator_mm_instance == NULL) { 
    283                 RETURN_FALSE; 
    284         } 
    285         do_session_unlock(TSRMLS_C); 
    286         RETURN_TRUE; 
    287 } 
    288  
    289 PHP_FUNCTION(_eaccelerator_session_read) 
    290 { 
    291         zval **arg_key; 
    292         char *key; 
    293         int len; 
    294  
    295         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg_key) == FAILURE) { 
    296                 WRONG_PARAM_COUNT; 
    297         } 
    298         len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 
    299         key = do_alloca(len + 1); 
    300         strcpy(key, "sess_"); 
    301         strcat(key, Z_STRVAL_PP(arg_key)); 
    302         do_session_lock(key TSRMLS_CC); 
    303         if (eaccelerator_get(key, len, return_value, eaccelerator_sessions_cache_place TSRMLS_CC)) { 
    304                 free_alloca(key); 
    305                 return; 
    306         } else { 
    307                 free_alloca(key); 
    308                 RETURN_EMPTY_STRIN (); 
    309         } 
    310 } 
    311  
    312 PHP_FUNCTION(_eaccelerator_session_write) 
    313 { 
    314         zval **arg_key, **arg_val; 
    315         char *key; 
    316         int len; 
    317         time_t ttl; 
    318  
    319         if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg_key, &arg_val) == FAILURE) { 
    320                 WRONG_PARAM_COUNT; 
    321         } 
    322         len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 
    323         key = do_alloca(len + 1); 
    324         strcpy(key, "sess_"); 
    325         strcat(key, Z_STRVAL_PP(arg_key)); 
    326         ttl = PS(gc_maxlifetime); 
    327         if (ttl < 0) 
    328                 ttl = 1440; 
    329         do_session_lock(key TSRMLS_CC); 
    330         if (eaccelerator_put(key, len, *arg_val, ttl, eaccelerator_sessions_cache_place TSRMLS_CC)) { 
    331                 free_alloca(key); 
    332                 RETURN_TRUE; 
    333         } else { 
    334                 free_alloca(key); 
    335                 RETURN_FALSE; 
    336         } 
    337 } 
    338  
    339 PHP_FUNCTIO (_eaccelerator_session_destroy) 
    340 { 
    341         zval **arg_key; 
    342         char *key; 
    343         int len; 
    344  
    345         if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex (1, &arg_key) == FAILURE) { 
    346                 WRONG_PARAM_COUNT; 
    347         } 
    348         len = sizeof("sess_") + Z_STRLEN_PP(arg_key); 
    349         key = do_alloca(len + 1); 
    350         strcpy(key, "sess_"); 
    351         strcat(key, Z_STRVAL_PP(arg_key)); 
    352         if (eaccelerator_rm(key, len, eaccelerator_sessions_cache_place TSRMLS_CC)) { 
    353                 free_alloca(key); 
    354                 RETURN_TRUE; 
    355         } else { 
    356                 free_alloca(key); 
    357                 RETURN_FALSE; 
    358         } 
    359 } 
    360  
    361 PHP_FUNCTION(_eaccelerator_session_gc) 
    362 { 
    363         if (eaccelerator_mm_instance == NULL) { 
    364                 RETURN_FALSE; 
    365         } 
    366         eaccelerator_gc(TSRMLS_C); 
    367         RETURN_TRUE; 
    368 } 
    369 #endif /* ELSE HAVE_PHP_SESSIONS_SUPPORT */ 
    370258 
    371259ps_module ps_mod_eaccelerator = { 
    372 #ifdef PS_CREATE_SID_ARGS 
    373         PS_MOD_SID (eaccelerator) 
    374 #else 
    375         PS_MOD (eaccelerator) 
    376 #endif 
     260        PS_MOD_SID(eaccelerator) 
    377261}; 
    378  
    379 /* is the eA registered as session handler */ 
    380 int eaccelerator_session_registered() 
    381 { 
    382         return !(eaccelerator_sessions_cache_place != ea_none && eaccelerator_sessions_registered == 0); 
    383 } 
    384262 
    385263/* register ea as session handler */ 
    386264void eaccelerator_register_session() 
    387265{ 
    388         php_session_register_module(&ps_mod_eaccelerator); 
    389         eaccelerator_sessions_registered = 1; 
    390 
    391  
    392 /* register ea as the custom session handler */ 
    393 int eaccelerator_set_session_handlers(TSRMLS_D) 
    394 
    395         zval func; 
    396         zval retval; 
    397         int ret = 1; 
    398 #ifdef HAVE_PHP_SESSIONS_SUPPORT        // do it with the session api 
    399         zval param; 
    400         zval *params[1]; 
    401  
    402         if (eaccelerator_sessions_cache_place == ea_none) { 
    403                 return 0; 
    404         } 
    405         ZVAL_STRING(&func, "session_module_name", 0); 
    406         INIT_ZVAL(param); 
    407         params[0] = &param; 
    408         ZVAL_STRING(params[0], "eaccelerator", 0); 
    409         if (call_user_function(EG (function_table), NULL, &func, &retval, 1, params TSRMLS_CC) == FAILURE) { 
    410                 ret = 0; 
    411         } 
    412         zval_dtor(&retval); 
    413         return ret; 
    414 #else // register the functions as custom user functions 
    415         zval *params[6]; 
    416         int i; 
    417  
    418         if (eaccelerator_sessions_cache_place == eaccelerator_none) { 
    419                 return 0; 
    420         } 
    421         if (eaccelerator_mm_instance == NULL) { 
    422                 return 0; 
    423         } 
    424         if (!zend_hash_exists(EG (function_table), "session_set_save_handler", sizeof("session_set_save_handler"))) { 
    425                 return 0; 
    426         } 
    427  
    428         ZVAL_STRING(&func, "session_set_save_handler", 0); 
    429         MAKE_STD_ZVAL(params[0]); 
    430         ZVAL_STRING(params[0], "_eaccelerator_session_open", 1); 
    431         MAKE_STD_ZVAL(params[1]); 
    432         ZVAL_STRING(params[1], "_eaccelerator_session_close", 1); 
    433         MAKE_STD_ZVAL(params[2]); 
    434         ZVAL_STRING(params[2], "_eaccelerator_session_read", 1); 
    435         MAKE_STD_ZVAL(params[3]); 
    436         ZVAL_STRING(params[3], "_eaccelerator_session_write", 1); 
    437         MAKE_STD_ZVAL(params[4]); 
    438         ZVAL_STRING(params[4], "_eaccelerator_session_destroy", 1); 
    439         MAKE_STD_ZVAL(params[5]); 
    440         ZVAL_STRING(params[5], "_eaccelerator_session_gc", 1); 
    441         if (call_user_function(EG (function_table), NULL, &func, &retval, 6, params TSRMLS_CC) == FAILURE) { 
    442                 ret = 0; 
    443         } 
    444         zval_dtor (&retval); 
    445         for (i = 0; i < 6; i++) 
    446                 zval_ptr_dtor(&params[i]); 
    447         return ret; 
    448 #endif 
    449 
    450  
    451 /* function to call from a php script to register ea as session handler */ 
    452 PHP_FUNCTION(eaccelerator_set_session_handlers) 
    453 
    454         if (eaccelerator_set_session_handlers(TSRMLS_C)) { 
    455                 RETURN_TRUE; 
    456         } else { 
    457                 RETURN_FALSE; 
     266        if (eaccelerator_sessions_cache_place != ea_none && eaccelerator_sessions_registered == 0) { 
     267                if (php_session_register_module(&ps_mod_eaccelerator) != 0) { 
     268                        zend_error(E_CORE_ERROR, "Could not register eAccelerator session handler!");    
     269                } 
     270                eaccelerator_sessions_registered = 1; 
     271                return; 
    458272        } 
    459273} 
  • eaccelerator/trunk/session.h

    r182 r258  
    3131#include "php_ini.h" 
    3232 
    33 /* check if php is compiled with session support */ 
    34 #undef HAVE_PHP_SESSIONS_SUPPORT 
    35 #if defined(HAVE_EXT_SESSION_PHP_SESSION_H) 
    36 #       include "ext/session/php_session.h" 
    37 #       if defined(PHP_SESSION_API) && PHP_SESSION_API >= 20020306 
    38 #       define HAVE_PHP_SESSIONS_SUPPORT 
    39 #       endif 
    40 #else // no session support in php, undef eA session support 
    41 #       undef WITH_EACCELERATOR_SESSIONS 
    42 #endif 
    43  
    4433#ifdef WITH_EACCELERATOR_SESSIONS 
    4534 
    46 int eaccelerator_set_session_handlers(); 
     35#include "ext/session/php_session.h" 
     36 
    4737int eaccelerator_session_registered(); 
    4838void eaccelerator_register_session(); 
    4939 
    50 #ifdef HAVE_PHP_SESSIONS_SUPPORT 
    51 PHP_FUNCTION(_eaccelerator_session_open); 
    52 PHP_FUNCTION(_eaccelerator_session_close); 
    53 PHP_FUNCTION(_eaccelerator_session_read); 
    54 PHP_FUNCTION(_eaccelerator_session_write); 
    55 PHP_FUNCTION(_eaccelerator_session_destroy); 
    56 PHP_FUNCTION(_eaccelerator_session_gc); 
    57 #endif 
    58 PHP_FUNCTION(eaccelerator_set_session_handlers); 
    5940PHP_INI_MH(eaccelerator_OnUpdateSessionCachePlace); 
    6041