Add session_write_close(). This is primarily intended to enable

script writers to release the lock associated with the session lock
before the request finishes.

You can pass arrays now to session_set_save_handler(), so that the handlers
can be located in an object for better abstraction.
This commit is contained in:
Sascha Schumann 2000-10-11 19:47:15 +00:00
parent 0fd6a7ed18
commit d2d5320ee8
4 changed files with 34 additions and 30 deletions

View file

@ -49,26 +49,18 @@ ps_module ps_mod_user = {
} }
static zval *ps_call_handler(char *name, int argc, zval **argv) static zval *ps_call_handler(zval *func, int argc, zval **argv)
{ {
int i; int i;
zval *retval = NULL; zval *retval = NULL;
ELS_FETCH(); ELS_FETCH();
if (name && name[0] != '\0') { MAKE_STD_ZVAL(retval);
zval *func; if (call_user_function(EG(function_table), NULL, func, retval,
argc, argv) == FAILURE) {
SESS_ZVAL_STRING(name, func); zval_dtor(retval);
MAKE_STD_ZVAL(retval); efree(retval);
retval = NULL;
if (call_user_function(EG(function_table), NULL, func, retval,
argc, argv) == FAILURE) {
zval_dtor(retval);
efree(retval);
retval = NULL;
}
zval_dtor(func);
efree(func);
} }
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
@ -118,7 +110,7 @@ PS_CLOSE_FUNC(user)
retval = ps_call_handler(PSF(close), 0, NULL); retval = ps_call_handler(PSF(close), 0, NULL);
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
efree(mdata->names[i]); zval_del_ref(&mdata->names[i]);
efree(mdata); efree(mdata);
PS_SET_MOD_DATA(NULL); PS_SET_MOD_DATA(NULL);

View file

@ -20,14 +20,14 @@
#define MOD_USER_H #define MOD_USER_H
typedef union { typedef union {
char *names[6]; zval *names[6];
struct { struct {
char *ps_open; zval *ps_open;
char *ps_close; zval *ps_close;
char *ps_read; zval *ps_read;
char *ps_write; zval *ps_write;
char *ps_destroy; zval *ps_destroy;
char *ps_gc; zval *ps_gc;
} name; } name;
} ps_user; } ps_user;

View file

@ -115,6 +115,7 @@ PHP_FUNCTION(session_set_save_handler);
PHP_FUNCTION(session_cache_limiter); PHP_FUNCTION(session_cache_limiter);
PHP_FUNCTION(session_set_cookie_params); PHP_FUNCTION(session_set_cookie_params);
PHP_FUNCTION(session_get_cookie_params); PHP_FUNCTION(session_get_cookie_params);
PHP_FUNCTION(session_write_close);
#ifdef ZTS #ifdef ZTS
#define PSLS_D php_ps_globals *ps_globals #define PSLS_D php_ps_globals *ps_globals

View file

@ -65,6 +65,7 @@ function_entry session_functions[] = {
PHP_FE(session_cache_limiter, NULL) PHP_FE(session_cache_limiter, NULL)
PHP_FE(session_set_cookie_params, NULL) PHP_FE(session_set_cookie_params, NULL)
PHP_FE(session_get_cookie_params, NULL) PHP_FE(session_get_cookie_params, NULL)
PHP_FE(session_write_close, NULL)
{0} {0}
}; };
@ -1082,10 +1083,10 @@ PHP_FUNCTION(session_set_save_handler)
mdata = emalloc(sizeof(*mdata)); mdata = emalloc(sizeof(*mdata));
for (i = 0; i < 6; i++) { for (i = 0; i < 6; i++) {
convert_to_string_ex(args[i]); ZVAL_ADDREF(*args[i]);
mdata->names[i] = estrdup(Z_STRVAL_PP(args[i])); mdata->names[i] = *args[i];
} }
PS(mod_data) = (void *) mdata; PS(mod_data) = (void *) mdata;
RETURN_TRUE; RETURN_TRUE;
@ -1390,15 +1391,25 @@ PHP_RINIT_FUNCTION(session)
return SUCCESS; return SUCCESS;
} }
static void php_session_flush(PSLS_D)
{
if (PS(nr_open_sessions) > 0) {
php_session_save_current_state(PSLS_C);
PS(nr_open_sessions)--;
}
}
PHP_FUNCTION(session_write_close)
{
PSLS_FETCH();
php_session_flush(PSLS_C);
}
PHP_RSHUTDOWN_FUNCTION(session) PHP_RSHUTDOWN_FUNCTION(session)
{ {
PSLS_FETCH(); PSLS_FETCH();
if (PS(nr_open_sessions) > 0) { php_session_flush(PSLS_C);
php_session_save_current_state(PSLS_C);
PS(nr_open_sessions)--;
}
php_rshutdown_session_globals(PSLS_C); php_rshutdown_session_globals(PSLS_C);
return SUCCESS; return SUCCESS;
} }