Skip to content

Instantly share code, notes, and snippets.

@denysbutenko
Created March 9, 2013 19:19
Show Gist options
  • Save denysbutenko/5125377 to your computer and use it in GitHub Desktop.
Save denysbutenko/5125377 to your computer and use it in GitHub Desktop.
MODX Cache Refresh Script
<?php
$timeStart = microtime(true);
function downloadXML($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$retValue = curl_exec($ch);
curl_close($ch);
return $retValue;
}
function openPage($path){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$retValue = curl_exec($ch);
curl_close($ch);
return true;
}
$xmlPath = "YOUR XML URL";
$googleSitemapXML = downloadXML($xmlPath);
$xmlData = new SimpleXMLElement($googleSitemapXML);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rebuild MODX Cache</title>
<style>
#progressBar {
width:800px; height:20px; padding:1px; border:1px solid #000; overflow:hidden;
}
#progressBar div {
float:left;
border-left:1px solid #fff;
height:20px;
background-color:#F0F;
}
.clear { clear:both; }
</style>
</head>
<body style="font-family:Courier New, Courier, monospace;">
<div style="margin 0 auto;margin-top:20px;">
<?php
$totalURLS = count($xmlData->children());
$totalTime = $totalURLS*15/60;
$progressWidth = ceil(800 / $totalURLS) - 1;
echo "-----------------------------------------------<br />";
echo "REBUILD CACHE FOR ".$totalURLS." URLS<br />";
echo "Estimated Time: ".round($totalTime,0)." Minutes (be patient, do not refresh)<br />";
echo "-----------------------------------------------<br /><br />";
?>
<div id="progressBar">
<?php
foreach( $xmlData->children() AS $url )
{
if(openPage($url->loc)) {
echo "<div style=\"width:".$progressWidth."px;\" title=\"".$url->loc."\"></div>\n";
}
}
?>
<div class="clear"></div>
</div>
<?php
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br />";
echo "Total Time Elapsed: ". $time. " Seconds<br />";
echo "-----------------------------------------------<br />";
echo "&copy; 2013 developed by <a style=\"color:#000;\" href=\"http://www.cloudtec.ch\">cloudtec.ch</a>";
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment