Skip to content

cache.inc: cache_check_diskspace() uses undefined constant USER_HOST_TTL (PHP 8 fatal) #7317

Description

@FraSanga

Describe the bug

html/inc/cache.inc, in cache_check_diskspace():

$x = max(TEAM_PAGE_TTL, USER_PAGE_TTL, USER_HOST_TTL,
    USER_PROFILE_TTL, TOP_PAGES_TTL, INDEX_PAGE_TTL
);

USER_HOST_TTL is not defined anywhere in the tree — git grep USER_HOST_TTL returns only that one line. html/project.sample/cache_parameters.inc defines TEAM_PAGE_TTL, USER_PAGE_TTL, USER_PROFILE_TTL, TOP_PAGES_TTL, INDEX_PAGE_TTL, STATUS_PAGE_TTL, REMOTE_PROJECTS_TTL — but not USER_HOST_TTL. No caller passes it to get_cached_data() either; it looks like a cache category that was planned and never wired up.

On PHP 8 an undefined constant is a fatal Error (on PHP 7 it was an E_WARNING and evaluated to the string "USER_HOST_TTL", which max() harmlessly ignored among the integers).

Impact / reachability

cache_check_diskspace() returns early unless rand() % CACHE_SIZE_CHECK_FREQ == 0 (default 1 in 1000) and disk_usage("../cache") >= MAX_CACHE_USAGE (default 10 MB). So this only affects a project on the file cache backend (not memcached) once its html/cache/ dir grows past 10 MB — at which point roughly 1 request in 1000 returns HTTP 500 instead of pruning the cache. Narrow, but it's a live fatal and the pruning it was meant to do silently never happens.

Suggested fix

Drop USER_HOST_TTL from the max() list — nothing uses that TTL, so clean_cache()'s age threshold is unchanged in practice. (Alternatively add it to cache_parameters.inc, or wrap it in defined().)

Found while reviewing #6310; independent of that.


Reported with AI assistance (Claude Sonnet 5); verified against master @ b4b1bad96f.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

  • Status
    Backlog

Relationships

None yet

Development

No branches or pull requests

Issue actions