function AkamaiCacheControlClient::clear_url in Akamai 7
Same name and namespace in other branches
- 8 akamai.class.inc \AkamaiCacheControlClient::clear_url()
- 8.2 akamai.class.inc \AkamaiCacheControlClient::clear_url()
- 6.2 akamai.class.inc \AkamaiCacheControlClient::clear_url()
- 7.3 akamai.class.inc \AkamaiCacheControlClient::clear_url()
- 7.2 akamai.class.inc \AkamaiCacheControlClient::clear_url()
Clears the provided URLs from the Akamai Content Cache.
Parameters
$paths: A path (or array of paths) to clear from Akamai
Return value
An array with 2 keys: success: TRUE or FALSE indicating cache clearing success message: Blank if successful, the error message if not successful.
Overrides AkamaiCacheControl::clear_url
File
- ./
akamai.class.inc, line 67 - akamai.class.inc Akamai is a registered trademark of Akamai Technologies, Inc. This class is an abstraction around the Akamai Cache Control API.
Class
- AkamaiCacheControlClient
- Default implementation of the AkamaiCacheControl interface
Code
function clear_url($paths) {
// Grab params
extract($this->parameters);
// make paths an array
if (!is_array($paths)) {
$url = array(
$paths,
);
}
// prepend base path to paths to make URIs
$uris = array();
foreach ($paths as $path) {
$path = rtrim(preg_match("/^\\//", $path) ? $path : "/{$path}");
array_push($uris, $basepath . $path);
}
$opt = array(
"action={$action}",
"domain={$domain}",
"type={$type}",
);
if (!empty($email) && $email != AKAMAI_EMAIL_DISABLE) {
$opt[] = "email-notification={$email}";
}
//use SOAP protocol is Rest API is not default in the settings page
if ($restapi_default !== 1) {
try {
$ccuapi = new SoapClient($soap_wsdl, array(
'trace' => 1,
'features' => SOAP_USE_XSI_ARRAY_TYPE,
));
$response = $ccuapi
->purgeRequest($name, $pwd, '', $opt, $uris);
$is_success = $response->resultCode < 300;
if (!$is_success) {
throw new Exception($response->resultMsg);
}
foreach ($uris as $uri) {
watchdog('Akamai', t("Akamai %action of %uri: %message"), array(
'%uri' => $uri,
'%action' => $action,
'%message' => $response->resultMsg,
), WATCHDOG_NOTICE);
}
return array(
'success' => TRUE,
'code' => $response->resultCode,
'message' => $response->resultMsg,
);
} catch (Exception $e) {
watchdog('Akamai', t("Error Clearing Akamai Cache: %msg"), array(
'%msg' => $e
->getMessage(),
));
throw $e;
}
}
else {
$data = array(
"type" => "arl",
"action" => "{$action}",
"domain" => "{$domain}",
"objects" => $uris,
);
$data_string = json_encode($data);
$data_string = str_replace("\\/", '/', $data_string);
//url needs to be in the format of scheme://user:pass@url
$url_parsed = parse_url($restapi);
$url = $url_parsed['scheme'] . '://' . $name . ':' . $pwd . '@' . $url_parsed['host'] . $url_parsed['path'];
$response = drupal_http_request($url, array(
'method' => 'POST',
'data' => $data_string,
'timeout' => 5,
'headers' => array(
'Content-Type' => 'application/json',
'Content-Length' => strlen($data_string),
),
));
$is_success = $response->code < 300;
if (!$is_success) {
throw new Exception($response->data);
}
$response_data = json_decode($response->data);
watchdog('Akamai', t("Akamai RestAPI %action for %uris: Response: %response"), array(
'%uris' => implode(' ', $uris),
'%action' => $action,
'%response' => $response_data->detail,
), WATCHDOG_NOTICE);
}
}