summaryrefslogtreecommitdiff
path: root/ext/session/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/session/session.c')
-rw-r--r--ext/session/session.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/ext/session/session.c b/ext/session/session.c
index 5e4831c6be..52ba7e300a 100644
--- a/ext/session/session.c
+++ b/ext/session/session.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 1997-2015 The PHP Group |
+ | Copyright (c) 1997-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -477,6 +477,28 @@ PHPAPI int php_session_valid_key(const char *key) /* {{{ */
}
/* }}} */
+
+static void php_session_gc(void) /* {{{ */
+{
+ int nrand;
+
+ /* GC must be done before reading session data. */
+ if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) {
+ int nrdels = -1;
+
+ nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg());
+ if (nrand < PS(gc_probability)) {
+ PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
+#ifdef SESSION_DEBUG
+ if (nrdels != -1) {
+ php_error_docref(NULL, E_NOTICE, "purged %d expired session objects", nrdels);
+ }
+#endif
+ }
+ }
+} /* }}} */
+
+
static void php_session_initialize(void) /* {{{ */
{
zend_string *val = NULL;
@@ -521,6 +543,9 @@ static void php_session_initialize(void) /* {{{ */
php_session_reset_id();
PS(session_status) = php_session_active;
+ /* GC must be done before read */
+ php_session_gc();
+
/* Read data */
php_session_track_init();
if (PS(mod)->s_read(&PS(mod_data), PS(id), &val, PS(gc_maxlifetime)) == FAILURE) {
@@ -1513,7 +1538,6 @@ PHPAPI void php_session_start(void) /* {{{ */
zval *ppid;
zval *data;
char *p, *value;
- int nrand;
size_t lensess;
switch (PS(session_status)) {
@@ -1622,20 +1646,6 @@ PHPAPI void php_session_start(void) /* {{{ */
php_session_initialize();
php_session_cache_limiter();
-
- if ((PS(mod_data) || PS(mod_user_implemented)) && PS(gc_probability) > 0) {
- int nrdels = -1;
-
- nrand = (int) ((float) PS(gc_divisor) * php_combined_lcg());
- if (nrand < PS(gc_probability)) {
- PS(mod)->s_gc(&PS(mod_data), PS(gc_maxlifetime), &nrdels);
-#ifdef SESSION_DEBUG
- if (nrdels != -1) {
- php_error_docref(NULL, E_NOTICE, "purged %d expired session objects", nrdels);
- }
-#endif
- }
- }
}
/* }}} */