Welkom bij SinterKlaas Tips
Kies hier het bedrag dat je wilt besteden of kies een thema.
Sinterklaascadeautje zoeken?
// cache xml file
$sCacheFile = XML_LOCAL_CACHEFILE;
$sXMLFileLocation = XML_FEEDURL;
$sStatusFile = XML_LOCAL_STATUSFILE;
set_error_handler('handleError');
if (!is_writable($sCacheFile)) {
//chmod($sCacheFile, 0777);
}
$sStatusContent = '';
writeXmlFile(&$sStatusContent, &$sCacheFile);
if ($sStatusContent == '') {
$sStatusContent = 'CACHE '.(time() + 3600 *24);
}
// write status to file, at end of script
function writeXmlFile(&$sStatusContent, &$sCacheFile) {
if (!$handle = fopen($sCacheFile, 'w+')) {
// opening of cachefile failed, set status file to NOCACHE and include time to try again (one hour), until then: don't use cache.
$sStatusContent = 'NOCACHE '.(time() + 3600);
}
try {
$fwrite = fwrite($handle, @file_get_contents(XML_FEEDURL));
if ($fwrite === false) {
throw new Exception('Write failed');
} else {
$sStatusContent = 'CACHE '.(time() + 3600 *24);
}
} catch(Exception $e) {
// writing of xml file failed, set status file to NOCACHE and include time to try again (one hour), until then: don't use cache.
$sStatusContent = 'NOCACHE '.(time() + 3600);
}
fclose($handle);
}
function writeStatusFile(&$sStatusContent, &$sStatusFile) {
$handle = fopen($sStatusFile, 'w+');
@fwrite($handle, $sStatusContent);
fclose($handle);
}
function handleError($num,$err,$file,$line) {
global $sStatusContent;
$sStatusContent = 'NOCACHE '.(time() + 3600);
//echo 'Krijns cust error: '.$err.' in '.$file.' on line '.$line.'
';
}
writeStatusFile(&$sStatusContent, &$sStatusFile);
Sinterklaascadeautje zoeken?