Merge pull request #3846 from annando/session-destroy
Avoid warning "Failed to write session data"
This commit is contained in:
commit
22aa7f9f07
8
boot.php
8
boot.php
|
@ -904,8 +904,14 @@ function login($register = false, $hiddens = false) {
|
||||||
* @brief Used to end the current process, after saving session state.
|
* @brief Used to end the current process, after saving session state.
|
||||||
*/
|
*/
|
||||||
function killme() {
|
function killme() {
|
||||||
|
global $session_exists;
|
||||||
|
|
||||||
if (!get_app()->is_backend()) {
|
if (!get_app()->is_backend()) {
|
||||||
session_write_close();
|
if (!$session_exists) {
|
||||||
|
session_abort();
|
||||||
|
} else {
|
||||||
|
session_write_close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exit();
|
exit();
|
||||||
|
|
|
@ -24,17 +24,17 @@ function ref_session_read($id) {
|
||||||
if (is_object($memcache)) {
|
if (is_object($memcache)) {
|
||||||
$data = $memcache->get(get_app()->get_hostname().":session:".$id);
|
$data = $memcache->get(get_app()->get_hostname().":session:".$id);
|
||||||
if (!is_bool($data)) {
|
if (!is_bool($data)) {
|
||||||
|
$session_exists = true;
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
logger("no data for session $id", LOGGER_TRACE);
|
logger("no data for session $id", LOGGER_TRACE);
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
|
$r = dba::select('session', array('data'), array('sid' => $id), array('limit' => 1));
|
||||||
|
|
||||||
if (dbm::is_result($r)) {
|
if (dbm::is_result($r)) {
|
||||||
$session_exists = true;
|
$session_exists = true;
|
||||||
return $r[0]['data'];
|
return $r['data'];
|
||||||
} else {
|
} else {
|
||||||
logger("no data for session $id", LOGGER_TRACE);
|
logger("no data for session $id", LOGGER_TRACE);
|
||||||
}
|
}
|
||||||
|
@ -73,15 +73,12 @@ function ref_session_write($id, $data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($session_exists) {
|
if ($session_exists) {
|
||||||
$r = q("UPDATE `session`
|
$fields = array('data' => $data, 'expire' => $expire);
|
||||||
SET `data` = '%s', `expire` = '%s'
|
$condition = array("WHERE `sid` = ? AND (`data` != ? OR `expire` != ?)", $id, $data, $expire);
|
||||||
WHERE `sid` = '%s'
|
dba::update('session', $fields, $condition);
|
||||||
AND (`data` != '%s' OR `expire` != '%s')",
|
|
||||||
dbesc($data), dbesc($expire), dbesc($id), dbesc($data), dbesc($expire));
|
|
||||||
} else {
|
} else {
|
||||||
$r = q("INSERT INTO `session`
|
$fields = array('sid' => $id, 'expire' => $default_expire, 'data' => $data);
|
||||||
SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
|
dba::insert('session', $fields);
|
||||||
dbesc($id), dbesc($default_expire), dbesc($data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -99,14 +96,12 @@ function ref_session_destroy($id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
|
dba::delete('session', array('sid' => $id));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ref_session_gc($expire) {
|
function ref_session_gc($expire) {
|
||||||
q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
|
dba::delete('session', array("`expire` < ?", time()));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user