Skip to content

Commit d2d5320

Browse files
author
Sascha Schumann
committed
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.
1 parent 0fd6a7e commit d2d5320

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

ext/session/mod_user.c

+8-16
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,18 @@ ps_module ps_mod_user = {
4949
}
5050

5151

52-
static zval *ps_call_handler(char *name, int argc, zval **argv)
52+
static zval *ps_call_handler(zval *func, int argc, zval **argv)
5353
{
5454
int i;
5555
zval *retval = NULL;
5656
ELS_FETCH();
5757

58-
if (name && name[0] != '\0') {
59-
zval *func;
60-
61-
SESS_ZVAL_STRING(name, func);
62-
MAKE_STD_ZVAL(retval);
63-
64-
if (call_user_function(EG(function_table), NULL, func, retval,
65-
argc, argv) == FAILURE) {
66-
zval_dtor(retval);
67-
efree(retval);
68-
retval = NULL;
69-
}
70-
zval_dtor(func);
71-
efree(func);
58+
MAKE_STD_ZVAL(retval);
59+
if (call_user_function(EG(function_table), NULL, func, retval,
60+
argc, argv) == FAILURE) {
61+
zval_dtor(retval);
62+
efree(retval);
63+
retval = NULL;
7264
}
7365

7466
for (i = 0; i < argc; i++) {
@@ -118,7 +110,7 @@ PS_CLOSE_FUNC(user)
118110
retval = ps_call_handler(PSF(close), 0, NULL);
119111

120112
for (i = 0; i < 6; i++)
121-
efree(mdata->names[i]);
113+
zval_del_ref(&mdata->names[i]);
122114
efree(mdata);
123115

124116
PS_SET_MOD_DATA(NULL);

ext/session/mod_user.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
#define MOD_USER_H
2121

2222
typedef union {
23-
char *names[6];
23+
zval *names[6];
2424
struct {
25-
char *ps_open;
26-
char *ps_close;
27-
char *ps_read;
28-
char *ps_write;
29-
char *ps_destroy;
30-
char *ps_gc;
25+
zval *ps_open;
26+
zval *ps_close;
27+
zval *ps_read;
28+
zval *ps_write;
29+
zval *ps_destroy;
30+
zval *ps_gc;
3131
} name;
3232
} ps_user;
3333

ext/session/php_session.h

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ PHP_FUNCTION(session_set_save_handler);
115115
PHP_FUNCTION(session_cache_limiter);
116116
PHP_FUNCTION(session_set_cookie_params);
117117
PHP_FUNCTION(session_get_cookie_params);
118+
PHP_FUNCTION(session_write_close);
118119

119120
#ifdef ZTS
120121
#define PSLS_D php_ps_globals *ps_globals

ext/session/session.c

+18-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function_entry session_functions[] = {
6565
PHP_FE(session_cache_limiter, NULL)
6666
PHP_FE(session_set_cookie_params, NULL)
6767
PHP_FE(session_get_cookie_params, NULL)
68+
PHP_FE(session_write_close, NULL)
6869
{0}
6970
};
7071

@@ -1082,10 +1083,10 @@ PHP_FUNCTION(session_set_save_handler)
10821083
mdata = emalloc(sizeof(*mdata));
10831084

10841085
for (i = 0; i < 6; i++) {
1085-
convert_to_string_ex(args[i]);
1086-
mdata->names[i] = estrdup(Z_STRVAL_PP(args[i]));
1086+
ZVAL_ADDREF(*args[i]);
1087+
mdata->names[i] = *args[i];
10871088
}
1088-
1089+
10891090
PS(mod_data) = (void *) mdata;
10901091

10911092
RETURN_TRUE;
@@ -1390,15 +1391,25 @@ PHP_RINIT_FUNCTION(session)
13901391
return SUCCESS;
13911392
}
13921393

1393-
1394-
PHP_RSHUTDOWN_FUNCTION(session)
1394+
static void php_session_flush(PSLS_D)
13951395
{
1396-
PSLS_FETCH();
1397-
13981396
if (PS(nr_open_sessions) > 0) {
13991397
php_session_save_current_state(PSLS_C);
14001398
PS(nr_open_sessions)--;
14011399
}
1400+
}
1401+
1402+
PHP_FUNCTION(session_write_close)
1403+
{
1404+
PSLS_FETCH();
1405+
php_session_flush(PSLS_C);
1406+
}
1407+
1408+
PHP_RSHUTDOWN_FUNCTION(session)
1409+
{
1410+
PSLS_FETCH();
1411+
1412+
php_session_flush(PSLS_C);
14021413
php_rshutdown_session_globals(PSLS_C);
14031414
return SUCCESS;
14041415
}

0 commit comments

Comments
 (0)