forked from jquery/codeorigin.jquery.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge.php
28 lines (22 loc) · 811 Bytes
/
purge.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
require_once( 'netdnarws-php/NetDNA.php' );
$config = json_decode( file_get_contents( './config.json' ), true );
$config = $config[ 'cdn' ];
$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;
}
$file = $parts[ 0 ];
header( 'Content-Type: text/plain' );
echo "Attempting to purge: $zone_id: $file.\n";
$api = new NetDNA( 'jquery', $config[ 'consumer_key' ], $config[ 'consumer_secret' ] );
$result = $api->delete( '/zones/pull.json/' . $zone_id . '/cache', array( 'file' => $file ) );
$result = json_decode( $result, true );
if ( $result[ 'code' ] !== 200 ) {
echo 'Error reported: ' . print_r( $result, true );
} else {
echo "Done\n";
}