Trigger purge of an additional CDN
-
Hi there,
I have put a CDN in front of WordPress to leverage AWS WAF, Origin Shield and a few other features. To invalidate the CDN I used this function, credits to https://gist.github.com/claylo/1009169, which does its job but causes unwanted side effects during save process.
function albCdnFlush($post_ID, $new_status, $old_status) { if ( $new_status === "publish" || $old_status === "publish" ) { $access_key = 'MYKACCESSEY'; $secret_key = 'MYSECRETKEY'; $distribution = 'DISTRIBUTION-ID'; $epoch = date('U'); $xml = <<<EOD <InvalidationBatch> <Path>/*</Path> <CallerReference>{$distribution}{$epoch}</CallerReference> </InvalidationBatch> EOD; /** * You probably don't need to change anything below here. */ $len = strlen($xml); $date = gmdate('D, d M Y G:i:s T'); $sig = base64_encode( hash_hmac('sha1', $date, $secret_key, true) ); $msg = "POST /2010-11-01/distribution/{$distribution}/invalidation HTTP/1.0\r\n"; $msg .= "Host: cloudfront.amazonaws.com\r\n"; $msg .= "Date: {$date}\r\n"; $msg .= "Content-Type: text/xml; charset=UTF-8\r\n"; $msg .= "Authorization: AWS {$access_key}:{$sig}\r\n"; $msg .= "Content-Length: {$len}\r\n\r\n"; $msg .= $xml; $fp = fsockopen('ssl://cloudfront.amazonaws.com', 443, $errno, $errstr, 30 ); if (!$fp) { die("Connection failed: {$errno} {$errstr}\n"); } fwrite($fp, $msg); $resp = ''; while(! feof($fp)) { $resp .= fgets($fp, 1024); } fclose($fp); echo $resp; } } add_action( 'transition_post_status', 'albCdnFlush', 10, 3 );
I wonder, though, if I the existing W3Total Cache process(es) can be used but with different credentials, respectively another CDN ID?
Many thanks in advance
Mike
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Trigger purge of an additional CDN’ is closed to new replies.