Skip to content

Instantly share code, notes, and snippets.

@jdorfman
Created July 29, 2013 17:16
Show Gist options
  • Save jdorfman/6105911 to your computer and use it in GitHub Desktop.
Save jdorfman/6105911 to your computer and use it in GitHub Desktop.
<?php
//requires https://github.com/netdna/netdnarws-php
require_once('netdnarws-php/NetDNA.php');
//place your alias, key, secret into this constructor
$api = new NetDNA("{alias}","{consumer_key}","{consumer_secret}");
function purgeCacheFileFromCDN($id, $files = null) {
global $api;
//3 options for purge
$result = null;
if ($files == null){
$result = $api->delete('/zones/pull.json/'.$id.'/cache');
} else if (!is_array($files)){
//Purge single file
$params = array('file'=>$files);
$result = $api->delete('/zones/pull.json/'.$id.'/cache',$params);
} else if (is_array($files)){
//Purge multiple files
$params = array();
foreach ($files as $k=>$v) $params[$k] = $v;
$result = $api->delete('/zones/pull.json/'.$id.'/cache',$params);
}
$result = json_decode($result,true);
if ($result['code'] != 200) {
echo 'Error reported: '.print_r( $result, 1 );
} else {
echo "Done\n";
}
}
//set zone id that you want to purge
$zone_id = '{zone_id}';
//Purge complete zone
$files = null;
// or purge single file
//$files = '/{somefile.extension}';
// or purge multiple, specific files
//$files = array('file0' => '/{file.extension}','file1' => '/{file2.extension}', ... );
echo "Attempting to purge: ".$zone_id.": ";
purgeCacheFileFromCDN( $zone_id, $files );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment