Skip to content

Instantly share code, notes, and snippets.

@visualdensity
Forked from jasonrundell/php-akamai-purge.php
Last active September 9, 2016 14:36
Show Gist options
  • Select an option

  • Save visualdensity/4678094 to your computer and use it in GitHub Desktop.

Select an option

Save visualdensity/4678094 to your computer and use it in GitHub Desktop.
<?php
/**
* PHP Akamai Purge
*
* By: Jason Rundell <jason dot rundell (at) gmail dot com> http://jasonrundell.com @jasonrundell
* Started: December 20th 2011
* Fork me: https://github.com/jasonrundell/PHP-Akamai-Purge
* Cudos: https://github.com/hradtke http://hermanradtke.com @hermanradtke
* I came across https://bugs.php.net/bug.php?id=43910 while doing a Google search for
* other folks who have worked with Akamai's SOAP API and PHP. The original function
* pap_purge() function was started from the code hradtke@php.net provided publicly.
* Jan 9, 2012 - I did some digging and I believe we have https://github.com/hradtke
* to thank! How many hradtke could there be, right? :)
* Jan 9, 2012 - Emailed hradtke and it's confirmed. Thanks Herman Radtke!
* Jan 10, 2012 - Dustin Hood @dustinhood tweeted me with Akamai documentation
* and later in emails provided the method for getting email notifications.
*
* Server requirements:
* SOAP for PHP: http://php.net/manual/en/book.soap.php
* PHP: Version 5.X
*/
define('AKAMAI_USER' , 'user' );
define('AKAMAI_PASSWORD', 'pass');
define('AKAMAI_WSDL' , 'https://ccuapi.akamai.com/ccuapi-axis.wsdl');
/**
* PHP Akamai Purge (PAP)
*
* Simple method for purging URL(s)
*/
function pap_akamai_purge($url){
$client = new SoapClient(AKAMAI_WSDL);
$options = array(
'action=invalidate',
'email-notification=me@example.com',
'domain=production',
'type=arl'
);
try
{
$purgeResult = $client->purgeRequest(AKAMAI_USER, AKAMAI_PASSWORD, '', $options, array($url));
if ($purgeResult->resultCode==100) { // 100 = success
return "Purge Success for: $url</br>";
} else {
return "Something went wrong. Akamai purge request failed: $purgeResult->resultCode</br>";
}
} catch(SoapFault $e) {
return "Something went wrong. Akamai purge request failed: $e</br>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment