Skip to content

Coding standards #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"username": "admin",
"password": "secret",
"cdn": {
"alias": "jquery",
"consumer_key": "key",
"consumer_secret": "secret",
"zone_id": 1
"consumer_secret": "secret"
}
}
68 changes: 25 additions & 43 deletions purge.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,35 @@
<?php
//requires https://github.com/netdna/netdnarws-php
require_once('netdnarws-php/NetDNA.php');
require_once( 'netdnarws-php/NetDNA.php' );

$config = json_decode(file_get_contents('./config.json'), true);
$config = $config["cdn"];
$config = json_decode( file_get_contents( './config.json' ), true );
$config = $config[ 'cdn' ];
$zone_id = 1;

//place your alias, key, secret into this constructor
$api = new NetDNA($config["alias"], $config["consumer_key"], $config["consumer_secret"]);
$parts = preg_split( '/\?reload=?/', $_SERVER[ 'REQUEST_URI' ] );
if ( !$parts ) {
header( '400 Bad Request' );
echo $_SERVER[ 'REQUEST_URI' ] . ' is not a valid URI.';
exit;
}

function purgeCacheFileFromCDN($id, $files = null) {
$file = $parts[ 0 ];

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);
}
header( 'Content-Type: text/plain' );
echo "Attempting to purge: $zone_id: $file.\n";

$result = json_decode($result,true);
if ($result['code'] != 200) {
echo 'Error reported: '.print_r( $result, 1 );
} else {
echo "Done\n";
}
$api = new NetDNA( 'jquery', $config[ 'consumer_key' ], $config[ 'consumer_secret' ] );

if ( empty( $file ) ) {
// Purge all files
$result = $api->delete( '/zones/pull.json/' . $zone_id . '/cache' );
} else {
// Purge single file
$result = $api->delete( '/zones/pull.json/' . $zone_id . '/cache', array( 'file' => $file ) );
}

//set zone id that you want to purge
$zone_id = $config["zone_id"];

$parts = preg_split( "/\?reload=?/", $_SERVER["REQUEST_URI"] );
if ( !$parts ) {
header("400 Bad Request");
echo $_SERVER["REQUEST_URI"]." is not a valid URI";
exit;
$result = json_decode( $result, true );
if ( $result[ 'code' ] !== 200 ) {
echo 'Error reported: ' . print_r( $result, true );
} else {
echo 'Done\n';
}

$file = $parts[0];

header( "Content-Type: text/plain" );
echo "Attempting to purge: ".$zone_id.": ".$file."\n";
purgeCacheFileFromCDN( $zone_id, $file );