In Ubuntu Server and other systemd-based Linux distributions, the phpsessionclean.timer is a recurring systemd timer unit installed by the php-common package. This timer periodically invokes a shell script (/usr/lib/php/sessionclean) that scans the PHP session storage directories (typically /var/lib/php/sessions/) and purges expired session files based on the session.gc_maxlifetime directive configured in php.ini. While essential for traditional PHP-FPM deployments using file-based session storage, this timer introduces unnecessary operational overhead, disk I/O contention, and a false sense of session management on servers that have migrated to external session backends (Redis, Memcached, database-backed sessions) or on Ubuntu Server instances that no longer run PHP workloads at all. On high-traffic application servers using Redis-backed sessions, the timer wastes CPU cycles scanning an empty directory tree while Redis independently handles its own TTL-based key expiration.
This guide explains how to completely disable the phpsessionclean timer in Ubuntu Server, enforcing an absolute block on automated PHP session file garbage collection and eliminating unnecessary periodic disk I/O operations.
Stop and Mask the phpsessionclean Timer
Because this timer is managed by the php-common package and will be re-enabled by package updates or PHP version upgrades, a simple systemctl disable is insufficient to guarantee the timer will never re-activate. To enforce an absolute block, we must explicitly mask the unit.
- Log into your Ubuntu Server via SSH using an account with
sudoprivileges. - Stop the timer to halt any currently scheduled execution:
sudo systemctl stop phpsessionclean.timer - Stop the associated service unit that the timer invokes:
sudo systemctl stop phpsessionclean.service - Mask both the timer and service units. This symlinks them to
/dev/null, creating a hard block against future activation by package reinstallations, apt triggers, or manual invocations:sudo systemctl mask phpsessionclean.timer sudo systemctl mask phpsessionclean.service - Optional but recommended: If PHP is no longer required on the server at all, consider removing the
php-commonpackage entirely to eliminate the unit files from the filesystem:sudo apt purge php-common
Verify the Service Lockdown
By masking the timer and its associated service, you guarantee that systemd will completely reject any attempt to invoke periodic PHP session garbage collection, eliminating unnecessary disk I/O operations on servers using external session backends.
To verify the lockdown is successful, attempt to start the timer manually:
sudo systemctl start phpsessionclean.timer
Systemd will return a fatal error stating that the unit is masked (e.g., Failed to start phpsessionclean.timer: Unit phpsessionclean.timer is masked). Furthermore, running systemctl list-timers --all will confirm that the phpsessionclean.timer is completely absent from the active timers list. The server’s disk I/O pipeline is now strictly optimised for production workloads without redundant session file scanning.