phpgt / phpgt/Session

Clean up filesystem when near capacity

Open
#283 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
PHP
Stars
1
Forks
1
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the write() entry point and inspect how the session directory and configuration are handled; the issue proposes cleanIfFilesystemFull() and a marker/lock file in that directory. Check config.default.ini and application config.ini files for configurable thresholds and batch sizes. Done means cleanup is bounded, hourly and locked, and removes old session files when usage reaches the stated threshold.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.