예제 #1
0
 function gc($maxlifetime)
 {
     $conn =& ADODB_Session::_conn();
     $debug = ADODB_Session::debug();
     $expire_notify = ADODB_Session::expireNotify();
     $optimize = ADODB_Session::optimize();
     $sync_seconds = ADODB_Session::syncSeconds();
     $table = ADODB_Session::table();
     if (!$conn) {
         return false;
     }
     $time = time();
     $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
     if ($expire_notify) {
         reset($expire_notify);
         $fn = next($expire_notify);
         $savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
         $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time}";
         $rs =& $conn->Execute($sql);
         ADODB_Session::_dumprs($rs);
         $conn->SetFetchMode($savem);
         if ($rs) {
             $conn->StartTrans();
             $keys = array();
             while (!$rs->EOF) {
                 $ref = $rs->fields[0];
                 $key = $rs->fields[1];
                 $fn($ref, $key);
                 $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key));
                 $rs->MoveNext();
             }
             $rs->Close();
             $conn->CompleteTrans();
         }
     } else {
         if (1) {
             $sql = "SELECT sesskey FROM {$table} WHERE expiry < {$time}";
             $arr =& $conn->GetAll($sql);
             foreach ($arr as $row) {
                 $sql2 = "DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0');
                 $conn->Execute($sql2, array($row[0]));
             }
         } else {
             $sql = "DELETE FROM {$table} WHERE expiry < {$time}";
             $rs =& $conn->Execute($sql);
             ADODB_Session::_dumprs($rs);
             if ($rs) {
                 $rs->Close();
             }
         }
         if ($debug) {
             ADOConnection::outp("<p><b>Garbage Collection</b>: {$sql}</p>");
         }
     }
     // suggested by Cameron, "GaM3R" <*****@*****.**>
     if ($optimize) {
         $driver = ADODB_Session::driver();
         if (preg_match('/mysql/i', $driver)) {
             $sql = "OPTIMIZE TABLE {$table}";
         }
         if (preg_match('/postgres/i', $driver)) {
             $sql = "VACUUM {$table}";
         }
         if (!empty($sql)) {
             $conn->Execute($sql);
         }
     }
     if ($sync_seconds) {
         $sql = 'SELECT ';
         if ($conn->dataProvider === 'oci8') {
             $sql .= "TO_CHAR({$conn->sysTimeStamp}, 'RRRR-MM-DD HH24:MI:SS')";
         } else {
             $sql .= $conn->sysTimeStamp;
         }
         $sql .= " FROM {$table}";
         $rs =& $conn->SelectLimit($sql, 1);
         if ($rs && !$rs->EOF) {
             $dbts = reset($rs->fields);
             $rs->Close();
             $dbt = $conn->UnixTimeStamp($dbts);
             $t = time();
             if (abs($dbt - $t) >= $sync_seconds) {
                 $msg = __FILE__ . ": Server time for webserver {$_SERVER['HTTP_HOST']} not in synch with database: " . " database={$dbt} ({$dbts}), webserver={$t} (diff=" . abs($dbt - $t) / 60 . ' minutes)';
                 error_log($msg);
                 if ($debug) {
                     ADOConnection::outp("<p>{$msg}</p>");
                 }
             }
         }
     }
     return true;
 }
예제 #2
0
 static function gc($maxlifetime)
 {
     $conn = ADODB_Session::_conn();
     $debug = ADODB_Session::debug();
     $expire_notify = ADODB_Session::expireNotify();
     $optimize = ADODB_Session::optimize();
     $table = ADODB_Session::table();
     if (!$conn) {
         return false;
     }
     $debug = ADODB_Session::debug();
     if ($debug) {
         $conn->debug = 1;
         $COMMITNUM = 2;
     } else {
         $COMMITNUM = 20;
     }
     //assert('$table');
     $time = $conn->OffsetDate(-$maxlifetime / 24 / 3600, $conn->sysTimeStamp);
     $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
     if ($expire_notify) {
         reset($expire_notify);
         $fn = next($expire_notify);
     } else {
         $fn = false;
     }
     $savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
     $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time} ORDER BY 2";
     # add order by to prevent deadlock
     $rs = $conn->SelectLimit($sql, 1000);
     if ($debug) {
         ADODB_Session::_dumprs($rs);
     }
     $conn->SetFetchMode($savem);
     if ($rs) {
         $tr = $conn->hasTransactions;
         if ($tr) {
             $conn->BeginTrans();
         }
         $keys = array();
         $ccnt = 0;
         while (!$rs->EOF) {
             $ref = $rs->fields[0];
             $key = $rs->fields[1];
             if ($fn) {
                 $fn($ref, $key);
             }
             $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key));
             $rs->MoveNext();
             $ccnt += 1;
             if ($tr && $ccnt % $COMMITNUM == 0) {
                 if ($debug) {
                     echo "Commit<br>\n";
                 }
                 $conn->CommitTrans();
                 $conn->BeginTrans();
             }
         }
         $rs->Close();
         if ($tr) {
             $conn->CommitTrans();
         }
     }
     // suggested by Cameron, "GaM3R" <*****@*****.**>
     if ($optimize) {
         $driver = ADODB_Session::driver();
         if (preg_match('/mysql/i', $driver)) {
             $sql = "OPTIMIZE TABLE {$table}";
         }
         if (preg_match('/postgres/i', $driver)) {
             $sql = "VACUUM {$table}";
         }
         if (!empty($sql)) {
             $conn->Execute($sql);
         }
     }
     return true;
 }
예제 #3
0
} else {
    $_SESSION['MONKEY'][0] += 1;
}
if (!isset($_GET['nochange'])) {
    @($_SESSION['AVAR'] += 1);
}
### START DISPLAY
print "<h3>PHP " . PHP_VERSION . "</h3>";
print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>";
print "<hr /> <b>Cookies</b>: ";
print_r($_COOKIE);
var_dump($_SESSION['MONKEY']);
### RANDOMLY PERFORM Garbage Collection
### In real-production environment, this is done for you
### by php's session extension, which calls adodb_sess_gc()
### automatically for you. See php.ini's
### session.cookie_lifetime and session.gc_probability
if (rand() % 5 == 0) {
    print "<hr /><p><b>Garbage Collection</b></p>";
    adodb_sess_gc(10);
    if (rand() % 2 == 0) {
        print "<p>Random own session destroy</p>";
        session_destroy();
    }
} else {
    $DB = ADODB_Session::_conn();
    $sessk = $DB->qstr('%AZ' . rand() . time());
    $olddate = $DB->DBTimeStamp(time() - 30 * 24 * 3600);
    $rr = $DB->qstr(rand());
    $DB->Execute("insert into {$options['table']} (sesskey,expiry,expireref,sessdata,created,modified) values ({$sessk},{$olddate}, {$rr},'',{$olddate},{$olddate})");
}
예제 #4
0
 function gc($maxlifetime)
 {
     $conn =& ADODB_Session::_conn();
     $debug = ADODB_Session::debug();
     $expire_notify = ADODB_Session::expireNotify();
     $optimize = ADODB_Session::optimize();
     $table = ADODB_Session::table();
     if (!$conn) {
         return false;
     }
     //assert('$table');
     $time = $conn->sysTimeStamp;
     $binary = $conn->dataProvider === 'mysql' ? '/*! BINARY */' : '';
     if ($expire_notify) {
         reset($expire_notify);
         $fn = next($expire_notify);
         $savem = $conn->SetFetchMode(ADODB_FETCH_NUM);
         $sql = "SELECT expireref, sesskey FROM {$table} WHERE expiry < {$time}";
         $rs =& $conn->Execute($sql);
         ADODB_Session::_dumprs($rs);
         $conn->SetFetchMode($savem);
         if ($rs) {
             $conn->StartTrans();
             $keys = array();
             while (!$rs->EOF) {
                 $ref = $rs->fields[0];
                 $key = $rs->fields[1];
                 $fn($ref, $key);
                 $del = $conn->Execute("DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0'), array($key));
                 $rs->MoveNext();
             }
             $rs->Close();
             $conn->CompleteTrans();
         }
     } else {
         if (0) {
             $sql = "SELECT sesskey FROM {$table} WHERE expiry < {$time}";
             $arr =& $conn->GetAll($sql);
             foreach ($arr as $row) {
                 $sql2 = "DELETE FROM {$table} WHERE sesskey=" . $conn->Param('0');
                 $conn->Execute($sql2, array(reset($row)));
             }
         } else {
             $sql = "DELETE FROM {$table} WHERE expiry < {$time}";
             $rs =& $conn->Execute($sql);
             ADODB_Session::_dumprs($rs);
             if ($rs) {
                 $rs->Close();
             }
         }
         if ($debug) {
             ADOConnection::outp("<p><b>Garbage Collection</b>: {$sql}</p>");
         }
     }
     // suggested by Cameron, "GaM3R" <*****@*****.**>
     if ($optimize) {
         $driver = ADODB_Session::driver();
         if (preg_match('/mysql/i', $driver)) {
             $sql = "OPTIMIZE TABLE {$table}";
         }
         if (preg_match('/postgres/i', $driver)) {
             $sql = "VACUUM {$table}";
         }
         if (!empty($sql)) {
             $conn->Execute($sql);
         }
     }
     return true;
 }
예제 #5
0
 function adodb_session_regenerate_id()
 {
     $conn = ADODB_Session::_conn();
     if (!$conn) {
         return false;
     }
     $old_id = session_id();
     if (function_exists('session_regenerate_id')) {
         session_regenerate_id();
     } else {
         session_id(md5(uniqid(rand(), true)));
         $ck = session_get_cookie_params();
         setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);
         //@session_start();
     }
     $new_id = session_id();
     $ok = $conn->Execute('UPDATE ' . ADODB_Session::table() . ' SET sesskey=' . $conn->qstr($new_id) . ' WHERE sesskey=' . $conn->qstr($old_id));
     /* it is possible that the update statement fails due to a collision */
     if (!$ok) {
         session_id($old_id);
         if (empty($ck)) {
             $ck = session_get_cookie_params();
         }
         setcookie(session_name(), session_id(), false, $ck['path'], $ck['domain'], $ck['secure']);
         return false;
     }
     return true;
 }
예제 #6
0
 calc("Last Moderated Image", $sql);
 $table[] = array("Parameter" => '', "Value" => '');
 $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Images Submitted in last 24 hours", $sql, 600);
 $sql = "SELECT COUNT(DISTINCT user_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Image Contributors in last 24 hours", $sql, 3600);
 $sql = "SELECT COUNT(DISTINCT moderator_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 48 HOUR) and moderator_id > 0 and moderated > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Active Moderators in last 24 hours", $sql, 3600);
 $table[] = array("Parameter" => '', "Value" => '');
 $sql = "SELECT COUNT(*) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 7 DAY)";
 calc("Images Submitted in last 7 days", $sql, 3600 * 3);
 $sql = "SELECT COUNT(DISTINCT user_id) FROM gridimage WHERE submitted > DATE_SUB(NOW() , INTERVAL 7 DAY)";
 calc("Image Contributors in last 7 days", $sql, 3600 * 3);
 $table[] = array("Parameter" => '', "Value" => '');
 $sql = "SELECT COUNT(DISTINCT ipaddr) FROM sessions WHERE EXPIRY > UNIX_TIMESTAMP(DATE_SUB(NOW(),INTERVAL 24 MINUTE))";
 $db2 = ADODB_Session::_conn();
 $table[] = array("Parameter" => "Approx Visitors in last 24 <u>minutes</u>", "Value" => $db2->getOne($sql));
 $sql = "SELECT COUNT(DISTINCT user_id)-1 FROM autologin WHERE created > DATE_SUB(NOW(), INTERVAL 1 HOUR)";
 calc("Approx Regular Users visited in last hour", $sql);
 $table[] = array("Parameter" => '', "Value" => '');
 $sql = "SELECT COUNT(*) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 1 HOUR)";
 calc("Forum Posts in last hour", $sql);
 $sql = "SELECT COUNT(DISTINCT poster_id) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 1 HOUR)";
 calc("Forum Posters in last hour", $sql);
 $table[] = array("Parameter" => '', "Value" => '');
 $sql = "SELECT COUNT(*) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Forum Posts in last 24 hours", $sql);
 $sql = "SELECT COUNT(DISTINCT poster_id) FROM geobb_posts WHERE post_time > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Forum Posters in last 24 hours", $sql);
 $sql = "SELECT COUNT(DISTINCT user_id) FROM geobb_lastviewed WHERE ts > DATE_SUB(NOW() , INTERVAL 24 HOUR)";
 calc("Forum Viewers in last 24 hours", $sql);