Skip to content

Instantly share code, notes, and snippets.

@pixeline
Last active January 23, 2018 12:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pixeline/21edd369bafc6c77e228 to your computer and use it in GitHub Desktop.
Save pixeline/21edd369bafc6c77e228 to your computer and use it in GitHub Desktop.
Clears serverside caches (finetuned for wordpress on gandi.net simplehosting instances): Varnish, APC, WP Transients, WP Super Cache, W3 Total Cache
<?php
/* purge.php
* Clears serverside caches (finetuned for wordpress on gandi.net simplehosting instances): Varnish, APC, WP Transients, WP Super Cache, W3 Total Cache
*/
header("Cache-Control: max-age=1"); // don't cache ourself
error_reporting(E_ALL);
ini_set("display_errors", 1);
/****************************************
VARNISH CACHE
****************************************/
// Set to true to hide varnish result
define("SILENT", false);
?>
<html>
<body style="padding:2em;font-family: sans-serif">
<h1>Varnish Cache</h1>
<?php
// See: http://wiki.gandi.net/fr/simple/cache
$purge_url = "http://" . $_SERVER["HTTP_HOST"] . "/";
if ( $ch = curl_init($purge_url) ) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PURGE");
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_NOBODY, SILENT);
curl_exec($ch);
curl_close($ch);
}
/****************************************
APC OPCODE CACHE
****************************************/
if ( function_exists('apc_clear_cache') ) {
?><hr><h1>APC Opcode Cache</h1><?php
echo (apc_clear_cache()) ? "<p style='color:#00CC00;'>APC System Cache purged." : "<p style='color:red;'>Failed to purge APC System cache";
echo (apc_clear_cache('user')) ? "<p style='color:#00CC00;'>APC User cache purged." : "<p style='color:red;'>Failed to purge APC User cache";
}
/****************************************
WORDPRESS TRANSIENTS
****************************************/
define( 'DIEONDBERROR', true );
?>
<h1>Wordpress Transients</h1>
<?
require_once("wp-load.php");
$wpdb->show_errors();
$query = "DELETE FROM `{$table_prefix}options` WHERE `option_name` LIKE ('%\_transient\_%');";
$result = $wpdb->query($query);
if($result== true ){
echo "<p style='color:#00CC00;'>$result transients removed.";
}else{
echo "<p>Error while cleaning up transients : ". var_export( $wpdb->print_error, true );
}
/****************************************
WORDPRESS SUPER CACHE
****************************************/
?>
<h1>Wordpress Cache plugins</h1>
<h2>WP Super Cache</h2><?php
if ( function_exists('wp_cache_clear_cache') ) {
$result = wp_cache_clear_cache();
print_r($result);
echo "<p style='color:#00CC00;'>WP Super Cache cleared. $result";
} else{
echo "<p>WP Super Cache plugin not detected.</p>";
}
?>
<h2>W3 Total Cache</h2>
<?php
/****************************************
W3 TOTAL CACHE plugin
****************************************/
if(function_exists('w3tc_pgcache_flush')){
$result = w3tc_pgcache_flush();
print_r($result);
echo "<p style='color:#00CC00;'>W3 Total Cache cleared. $result";
} else{
echo "<p>W3 Total Cache plugin not detected.</p>";
}
?>
<footer style="border-top:1px solid #DDD;padding:1em;font-size:80%">script by <a href="://pixeline.be">pixeline</a> - available on <a href="https://gist.github.com/pixeline/21edd369bafc6c77e228">github</a></footer>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment