本文整理汇总了PHP中Core\Session\manager::gc方法的典型用法代码示例。如果您正苦于以下问题:PHP manager::gc方法的具体用法?PHP manager::gc怎么用?PHP manager::gc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core\Session\manager
的用法示例。
在下文中一共展示了manager::gc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute()
{
global $DB;
$timenow = time();
\core\session\manager::gc();
// Cleanup old session linked tokens.
// Deletes the session linked tokens that are over a day old.
$DB->delete_records_select('external_tokens', 'lastaccess < :onedayago AND tokentype = :tokentype', array('onedayago' => $timenow - DAYSECS, 'tokentype' => EXTERNAL_TOKEN_EMBEDDED));
}
示例2: cron_run
//.........这里部分代码省略.........
}
// Delete old backup_controllers and logs.
$loglifetime = get_config('backup', 'loglifetime');
if (!empty($loglifetime)) {
// Value in days.
$loglifetime = $timenow - $loglifetime * 3600 * 24;
// Delete child records from backup_logs.
$DB->execute("DELETE FROM {backup_logs}\n WHERE EXISTS (\n SELECT 'x'\n FROM {backup_controllers} bc\n WHERE bc.backupid = {backup_logs}.backupid\n AND bc.timecreated < ?)", array($loglifetime));
// Delete records from backup_controllers.
$DB->execute("DELETE FROM {backup_controllers}\n WHERE timecreated < ?", array($loglifetime));
mtrace(" Deleted old backup records");
}
// Delete old cached texts
if (!empty($CFG->cachetext)) {
// Defined in config.php
$cachelifetime = time() - $CFG->cachetext - 60;
// Add an extra minute to allow for really heavy sites
$DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
mtrace(" Deleted old cache_text records");
}
if (!empty($CFG->usetags)) {
require_once $CFG->dirroot . '/tag/lib.php';
tag_cron();
mtrace(' Executed tag cron');
}
// Context maintenance stuff
context_helper::cleanup_instances();
mtrace(' Cleaned up context instances');
context_helper::build_all_paths(false);
// If you suspect that the context paths are somehow corrupt
// replace the line below with: context_helper::build_all_paths(true);
mtrace(' Built context paths');
// Remove expired cache flags
gc_cache_flags();
mtrace(' Cleaned cache flags');
// Cleanup messaging
if (!empty($CFG->messagingdeletereadnotificationsdelay)) {
$notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay;
$DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime' => $notificationdeletetime));
mtrace(' Cleaned up read notifications');
}
mtrace(' Deleting temporary files...');
cron_delete_from_temp();
// Cleanup user password reset records
// Delete any reset request records which are expired by more than a day.
// (We keep recently expired requests around so we can give a different error msg to users who
// are trying to user a recently expired reset attempt).
$pwresettime = isset($CFG->pwresettime) ? $CFG->pwresettime : 1800;
$earliestvalid = time() - $pwresettime - DAYSECS;
$DB->delete_records_select('user_password_resets', "timerequested < ?", array($earliestvalid));
mtrace(' Cleaned up old password reset records');
mtrace("...finished clean-up tasks");
}
// End of occasional clean-up tasks
// Send login failures notification - brute force protection in moodle is weak,
// we should at least send notices early in each cron execution
if (notify_login_failures()) {
mtrace(' Notified login failures');
}
// Make sure all context instances are properly created - they may be required in auth, enrol, etc.
context_helper::create_instances();
mtrace(' Created missing context instances');
// Session gc.
mtrace("Running session gc tasks...");
\core\session\manager::gc();
mtrace("...finished stale session cleanup");
示例3: redirect
redirect("{$CFG->wwwroot}/{$CFG->admin}/");
} else {
if ($returnto === 'profile') {
if ($course->id != SITEID) {
$returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
} else {
$returnurl = new moodle_url('/user/profile.php', array('id' => $user->id));
}
} else {
$returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id));
}
redirect($returnurl);
}
}
} else {
\core\session\manager::gc();
// Remove stale sessions.
redirect("{$CFG->wwwroot}/{$CFG->admin}/user.php");
}
// Never reached..
}
// Make sure we really are on the https page when https login required.
$PAGE->verify_https_required();
// Display page header.
if ($user->id == -1 or $user->id != $USER->id) {
if ($user->id == -1) {
echo $OUTPUT->header();
} else {
$streditmyprofile = get_string('editmyprofile');
$userfullname = fullname($user, true);
$PAGE->set_heading($userfullname);
示例4: unset
if (!empty($USER->newadminuser)) {
unset($USER->newadminuser);
// Apply defaults again - some of them might depend on admin user info, backup, roles, etc.
admin_apply_default_settings(null, false);
// Admin account is fully configured - set flag here in case the redirect does not work.
unset_config('adminsetuppending');
// Redirect to admin/ to continue with installation.
redirect("$CFG->wwwroot/$CFG->admin/");
} else if (empty($SITE->fullname)) {
// Somebody double clicked when editing admin user during install.
redirect("$CFG->wwwroot/$CFG->admin/");
} else {
redirect("$CFG->wwwroot/user/view.php?id=$USER->id&course=$course->id");
}
} else {
\core\session\manager::gc(); // Remove stale sessions.
redirect("$CFG->wwwroot/$CFG->admin/user.php");
}
// Never reached..
}
// Make sure we really are on the https page when https login required.
$PAGE->verify_https_required();
// Display page header.
if ($user->id == -1 or ($user->id != $USER->id)) {
if ($user->id == -1) {
echo $OUTPUT->header();
} else {
$userfullname = fullname($user, true);
示例5: test_gc
public function test_gc()
{
global $CFG, $DB, $USER;
$this->resetAfterTest();
$this->setAdminUser();
$adminid = $USER->id;
$this->setGuestUser();
$guestid = $USER->id;
$this->setUser(0);
$CFG->sessiontimeout = 60 * 10;
$record = new \stdClass();
$record->state = 0;
$record->sid = md5('hokus1');
$record->sessdata = null;
$record->userid = $adminid;
$record->timecreated = time() - 60 * 60;
$record->timemodified = time() - 30;
$record->firstip = $record->lastip = '10.0.0.1';
$r1 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus2');
$record->userid = $adminid;
$record->timecreated = time() - 60 * 60;
$record->timemodified = time() - 60 * 20;
$r2 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus3');
$record->userid = $guestid;
$record->timecreated = time() - 60 * 60 * 60;
$record->timemodified = time() - 60 * 20;
$r3 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus4');
$record->userid = $guestid;
$record->timecreated = time() - 60 * 60 * 60;
$record->timemodified = time() - 60 * 10 * 5 - 60;
$r4 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus5');
$record->userid = 0;
$record->timecreated = time() - 60 * 5;
$record->timemodified = time() - 60 * 5;
$r5 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus6');
$record->userid = 0;
$record->timecreated = time() - 60 * 60;
$record->timemodified = time() - 60 * 10 - 10;
$r6 = $DB->insert_record('sessions', $record);
$record->sid = md5('hokus7');
$record->userid = 0;
$record->timecreated = time() - 60 * 60;
$record->timemodified = time() - 60 * 9;
$r7 = $DB->insert_record('sessions', $record);
\core\session\manager::gc();
$this->assertTrue($DB->record_exists('sessions', array('id' => $r1)));
$this->assertFalse($DB->record_exists('sessions', array('id' => $r2)));
$this->assertTrue($DB->record_exists('sessions', array('id' => $r3)));
$this->assertFalse($DB->record_exists('sessions', array('id' => $r4)));
$this->assertFalse($DB->record_exists('sessions', array('id' => $r5)));
$this->assertFalse($DB->record_exists('sessions', array('id' => $r6)));
$this->assertTrue($DB->record_exists('sessions', array('id' => $r7)));
}
示例6: session_gc
/**
* Session garbage collection
* - verify timeout for all users
* - kill sessions of all deleted users
* - kill sessions of users with disabled plugins or 'nologin' plugin
*
* @deprecated since 2.6
*/
function session_gc()
{
debugging('session_gc() is deprecated, use \\core\\session\\manager::gc() instead', DEBUG_DEVELOPER);
\core\session\manager::gc();
}
示例7: action
function action($action)
{
global $CFG;
get_enabled_auth_plugins(true);
// fix the list of enabled auths
if (empty($CFG->auth)) {
$authsenabled = array();
} else {
$authsenabled = explode(',', $CFG->auth);
}
if (!exists_auth_plugin($this->plugin)) {
return get_string('pluginnotinstalled', 'auth', $this->plugin);
}
switch ($action) {
case 'enable':
// add to enabled list
if (!in_array($this->plugin, $authsenabled)) {
$authsenabled[] = $this->plugin;
$authsenabled = array_unique($authsenabled);
set_config('auth', implode(',', $authsenabled));
}
break;
case 'disable':
// Remove from enabled list.
$key = array_search($this->plugin, $authsenabled);
if ($key !== false) {
unset($authsenabled[$key]);
set_config('auth', implode(',', $authsenabled));
}
if ($this->plugin == $CFG->registerauth) {
set_config('registerauth', '');
}
break;
}
\core\session\manager::gc();
// remove stale sessions
return 0;
}