Summary
Snippet cache files intermittently get ‘double content’ when MODx recreates them after their expiry time. This causes a PHP parsing error which takes down the whole site until the offending file is manually edited/deleted.
Steps to reproduce
It happens once every couple of weeks organically. Annoyingly, despite repeated attempts (deleting cache files + recreating by visiting site) I have been unable to replicate the issue manually.
Observed behavior
An example of one of the files that was updated with ‘double content’:
<?php if(time() > 1752680198){return null;} return array (
'remembered' => 1060167,
'total' => '1060174',
'figure' => 5.0,
);<?php if(time() > 1752680198){return null;} return array (
'remembered' => 1060167,
'total' => '1060174',
'figure' => 5.0,
);
The PHP error given was:
Parse error: syntax error, unexpected ‘<’, expecting end of file in /var/www/web2/html/core/cache/right_panels/total-tributes.cache.php on line 5
This behaviour started mid-July 2025. We haven’t made changes to the relevant code at all, and MODx version/add-ons/environment etc were last changed long before this issue started occurring.
Environment
MODx 3.1.2-pl, nginx 1.41.1, PHP 7.4.33, MySQL 8.0.43, Chrome Windows (latest).
General Thoughts & Musings
I’ve tried regular (3x weekly) cache clears from the MODx manager with no success.
So far the issue only affects one file at a time, and I have only seen this behaviour on cache files in a specific partition (‘right_panels’).
The snippets involved all make SQL queries via xPDO to grab a large amount of DB data, then attempt to cache it for future usage on the frontend. However, there’s no evidence of those SQL queries failing or timing out. When I run the same SQL queries manually they complete quickly enough every time.
I’ve stopped short of more drastic tests (disabling cache entirely, removing the snippets from site build, etc) due to the performance and functionality issues that would bring.
Due to the intermittent nature of the issue I’ve struggled to nail it down!
Can anybody help shed some light on what might be causing the ‘double content’ in the files?