Workaround for 0 byte files causing problems
Posted: Fri Aug 01, 2025 4:07 am
I have experienced random instances of files being uploaded from CumulusMX or created by update.php ending up as 0 bytes long, and this has various effects including the Current Conditions block displaying nothing. This persists until the errant 0 byte file is deleted.
I haven't found the root cause of these files becoming 0 bytes long, so I created a workaround to check the files and delete them if they are 0 bytes. This runs at the beginning of api.php.
The inserted code is as follows:
I hope this is of use, and if anyone finds the root cause of the 0 byte file please share
Cheers
...Steve
I haven't found the root cause of these files becoming 0 bytes long, so I created a workaround to check the files and delete them if they are 0 bytes. This runs at the beginning of api.php.
The inserted code is as follows:
Code: Select all
function deletezerolengthfile ($filename) {
// 20250801 Steve Parry. Added to use in script to delete random zero lengtyh files caused by inderminate bugs.
if (file_exists($filename)) {
// File exists, now check its size
if (filesize($filename) == 0) {
unlink($filename); //delete the file
error_log ("[api.php] ".$filename . " Deleted due to zero length." . "\r\n");
}
}
}// end function
// 20250801 Steve Parry. Tidy up any of the files of zero length that can cause errors.
deletezerolengthfile ($base."meteotemplateLive.txt");
deletezerolengthfile ($base."update/realtime.txt");
deletezerolengthfile ($base."update/realtimegauges.txt");
deletezerolengthfile ($base."update/websitedata.json");
deletezerolengthfile ($base."update/wxnow.txt");
deletezerolengthfile ($base."cache/apiCache.txt");
deletezerolengthfile ($base."cache/apiLog.txt");
deletezerolengthfile ($base."cache/updateLog.txt");
deletezerolengthfile ($base."cache/apiCache.txt");
// End insertionCheers
...Steve