]> granicus.if.org Git - php/commitdiff
Fixed a bug that would cause the sqlite session database to grow endlessly.
authorIlia Alshanetsky <iliaa@php.net>
Mon, 12 Jan 2004 22:48:58 +0000 (22:48 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 12 Jan 2004 22:48:58 +0000 (22:48 +0000)
ext/sqlite/sess_sqlite.c

index 15ab59c54d5630b462d27121c70b9cdfc6375cd8..86aed96cbdbdcede25eef0969b76b1f4ff8b9d1c 100644 (file)
@@ -24,6 +24,7 @@
 #if HAVE_PHP_SESSION
 
 #include "ext/session/php_session.h"
+#include "ext/standard/php_lcg.h"
 #include <sqlite.h>
 #define SQLITE_RETVAL(__r) ((__r) == SQLITE_OK ? SUCCESS : FAILURE)
 #define PS_SQLITE_DATA sqlite *db = (sqlite*)PS_GET_MOD_DATA()
@@ -173,7 +174,14 @@ PS_GC_FUNC(sqlite)
        rv = sqlite_exec_printf(db, 
                        "DELETE FROM session_data WHERE (%d - updated) > %d", 
                        NULL, NULL, NULL, t, maxlifetime);
-       
+
+       /* because SQLite does not actually clear the deleted data from the database 
+        * we need to occassionaly do so manually to prevent the sessions database 
+        * from endlessly growing.
+        */
+       if ((int) ((float) PS(gc_divisor) * PS(gc_divisor) * php_combined_lcg(TSRMLS_C)) < PS(gc_probability) {
+               rv = sqlite_exec_printf(db, "VACUUM", NULL, NULL, NULL);
+       }
        return SQLITE_RETVAL(rv);
 }