Use ini_get to retrieve the session path instead of using session_path (#7067)
When using session_path, the session must be active and will automatically activate the session. This is a better method so that the session is never started. Co-authored-by: Tim Fry <tim@fusionpbx.com>
This commit is contained in:
parent
841cc6527e
commit
bc5165572a
|
|
@ -41,23 +41,17 @@ class session {
|
||||||
public static function filesystem_maintenance(settings $settings): void {
|
public static function filesystem_maintenance(settings $settings): void {
|
||||||
$retention_days = $settings->get('session', 'filesystem_retention_days', '');
|
$retention_days = $settings->get('session', 'filesystem_retention_days', '');
|
||||||
if (!empty($retention_days) && is_numeric($retention_days)) {
|
if (!empty($retention_days) && is_numeric($retention_days)) {
|
||||||
|
|
||||||
//get the session location
|
//get the session location
|
||||||
if (session_status() === PHP_SESSION_ACTIVE) {
|
$session_location = ini_get('session.save_path');
|
||||||
//session should not normally be running already in a service
|
|
||||||
$session_location = session_save_path();
|
|
||||||
} else {
|
|
||||||
//session has to be started to get the path
|
|
||||||
session_start();
|
|
||||||
$session_location = session_save_path();
|
|
||||||
session_destroy();
|
|
||||||
}
|
|
||||||
//loop through all files and check the modified time
|
//loop through all files and check the modified time
|
||||||
$files = glob($session_location . '/sess_*');
|
$files = glob($session_location . '/sess_*');
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (maintenance_service::days_since_modified($file) > $retention_days) {
|
if (maintenance_service::days_since_modified($file) > $retention_days) {
|
||||||
//remove old file
|
//remove old file
|
||||||
if (unlink($file)) {
|
if (unlink($file)) {
|
||||||
maintenance_service::log_write(self::class, "Removed old session file $file");
|
maintenance_service::log_write(self::class, "Removed old session file $file that was older than $retention_days days");
|
||||||
} else {
|
} else {
|
||||||
maintenance_service::log_write(self::class, "Unable to remove old session file $file", null, maintenance_service::LOG_ERROR);
|
maintenance_service::log_write(self::class, "Unable to remove old session file $file", null, maintenance_service::LOG_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue