Changeset 258
- Timestamp:
- 07/30/06 16:35:03 (2 years ago)
- Files:
-
- eaccelerator/trunk/ChangeLog (modified) (1 diff)
- eaccelerator/trunk/config.m4 (modified) (3 diffs)
- eaccelerator/trunk/doc/php/session.php (deleted)
- eaccelerator/trunk/eaccelerator.c (modified) (3 diffs)
- eaccelerator/trunk/session.c (modified) (4 diffs)
- eaccelerator/trunk/session.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
eaccelerator/trunk/ChangeLog
r256 r258 9 9 * Remove some leftovers from restoring encoded scripts which only create 10 10 overhead without the loader. 11 * Clean up the session handler, removed old code for php < 4.3. 11 12 12 13 2006-07-29 Bart Vanbrabant <bart.vanbrabant at zoeloelip.be> eaccelerator/trunk/config.m4
r246 r258 107 107 AC_DEFINE(WITH_EACCELERATOR_INFO, 1, [Define if you want the information functions]) 108 108 fi 109 if test "$eaccelerator_sessions" = "yes"; then110 AC_DEFINE(WITH_EACCELERATOR_SESSIONS, 1, [Define if you like to use eAccelerator session handlers to store session's information in shared memory])111 fi112 109 if test "$eaccelerator_content_caching" = "yes"; then 113 110 AC_DEFINE(WITH_EACCELERATOR_CONTENT_CACHING, 1, [Define if you like to use eAccelerator content cachin API]) … … 138 135 #include <sys/types.h>],msg=yes,msg=no) 139 136 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 140 153 141 154 AC_MSG_CHECKING(whether union semun is defined in sys/sem.h) … … 326 339 AC_DEFINE(HAVE_MPROTECT, 1, [Define if ou have mprotect function]) 327 340 ]) 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"; then334 AC_DEFINE(HAVE_EXT_SESSION_PHP_SESSION_H, 1, [Define if you have the <ext/session/php_session.h> header file.])335 fi336 AC_MSG_RESULT([$msg])337 CPPFLAGS="$old_cppflags"338 339 341 fi eaccelerator/trunk/eaccelerator.c
r256 r258 1746 1746 #endif 1747 1747 } 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(); 1752 1751 #endif 1753 1752 #ifdef WITH_EACCELERATOR_CONTENT_CACHING … … 1757 1756 register_eaccelerator_as_zend_extension(); 1758 1757 } 1758 1759 1759 #ifdef ZEND_ENGINE_2 1760 1760 /* cache the properties_info destructor */ … … 1946 1946 PHP_FE(eaccelerator_removed_scripts, NULL) 1947 1947 PHP_FE(eaccelerator_list_keys, NULL) 1948 #endif1949 #ifdef WITH_EACCELERATOR_SESSIONS1950 #ifndef HAVE_PHP_SESSIONS_SUPPORT1951 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 #endif1958 PHP_FE(eaccelerator_set_session_handlers, NULL)1959 1948 #endif 1960 1949 #ifdef WITH_EACCELERATOR_CONTENT_CACHING eaccelerator/trunk/session.c
r254 r258 33 33 #include "cache.h" 34 34 #include "ext/standard/md5.h" 35 #include "ext/standard/php_lcg.h" 35 36 #include <fcntl.h> 36 37 37 38 #ifdef WIN32 38 39 # include "win32/time.h" 39 #endif40 41 #if defined(HAVE_PHP_SESSIONS_SUPPORT) && defined(PS_CREATE_SID_ARGS)42 # include "ext/standard/php_lcg.h"43 40 #endif 44 41 … … 93 90 } 94 91 95 #ifdef HAVE_PHP_SESSIONS_SUPPORT /* PHP_SESSION_API >= 20020306 */96 92 /******************************************************************************/ 97 93 /* Session api functions */ 98 94 /******************************************************************************/ 99 100 95 PS_OPEN_FUNC(eaccelerator) 101 96 { … … 199 194 } 200 195 201 #ifdef PS_CREATE_SID_ARGS202 196 PS_CREATE_SID_FUNC(eaccelerator) 203 197 { … … 262 256 return estrdup (buf); 263 257 } 264 #endif265 266 #else267 /******************************************************************************/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 */370 258 371 259 ps_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) 377 261 }; 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 }384 262 385 263 /* register ea as session handler */ 386 264 void eaccelerator_register_session() 387 265 { 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] = ¶m; 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(¶ms[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; 458 272 } 459 273 } eaccelerator/trunk/session.h
r182 r258 31 31 #include "php_ini.h" 32 32 33 /* check if php is compiled with session support */34 #undef HAVE_PHP_SESSIONS_SUPPORT35 #if defined(HAVE_EXT_SESSION_PHP_SESSION_H)36 # include "ext/session/php_session.h"37 # if defined(PHP_SESSION_API) && PHP_SESSION_API >= 2002030638 # define HAVE_PHP_SESSIONS_SUPPORT39 # endif40 #else // no session support in php, undef eA session support41 # undef WITH_EACCELERATOR_SESSIONS42 #endif43 44 33 #ifdef WITH_EACCELERATOR_SESSIONS 45 34 46 int eaccelerator_set_session_handlers(); 35 #include "ext/session/php_session.h" 36 47 37 int eaccelerator_session_registered(); 48 38 void eaccelerator_register_session(); 49 39 50 #ifdef HAVE_PHP_SESSIONS_SUPPORT51 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 #endif58 PHP_FUNCTION(eaccelerator_set_session_handlers);59 40 PHP_INI_MH(eaccelerator_OnUpdateSessionCachePlace); 60 41