public function write(string $sessionId, string $sessionData):bool {
if($sessionData === self::EMPTY_PHP_ARRAY) {
return true;
}
$this->cleanIfFilesystemFull();
$filePath = $this->getFilePath($sessionId);
$bytesWritten = file_put_contents($filePath, $sessionData);
return $bytesWritten !== false;
}
Where cleanIfFilesystemFull() checks disk_total_space($this->path) / disk_free_space($this->path), and if usage is >= 90%, deletes oldest session files until usage is below maybe 40%, or nothing is older than maybe 3 days, for example.
This should only be checked once per hour, using a marker file within the session directory. This marker file can be used as a lock file too, so only one request will be doing the cleanup.
There should be a maximum number of deletions per web request, as to not slow down traffic. The marker/lock file should not be reset until after then threshold is fixed. This way, the directory can be cleaned up only when usage exceeds a certain threshold, and the load of the work can be spread over different web requests.
The thresholds and batch sizes should all be configurable. In WebEngine this would be set in the config.default.ini and extended in application config.ini files.
Where
cleanIfFilesystemFull()checksdisk_total_space($this->path) / disk_free_space($this->path), and if usage is >= 90%, deletes oldest session files until usage is below maybe 40%, or nothing is older than maybe 3 days, for example.This should only be checked once per hour, using a marker file within the session directory. This marker file can be used as a lock file too, so only one request will be doing the cleanup.
There should be a maximum number of deletions per web request, as to not slow down traffic. The marker/lock file should not be reset until after then threshold is fixed. This way, the directory can be cleaned up only when usage exceeds a certain threshold, and the load of the work can be spread over different web requests.
The thresholds and batch sizes should all be configurable. In WebEngine this would be set in the
config.default.iniand extended in applicationconfig.inifiles.