如何使用php 5.3清除Akamai缓存? Akamai Github为php 5.6+提供的代码正在运行。但是在用于php 5.3的Akamai Github页面中提供的代码给出了错误。
错误行标记为“//”:
require_once'src / Authentication.php';
require_once'src / Authentication / Timestamp.php';
require_once'src / Authentication / Nonce.php';
require_once'src / Exception / ConfigException.php';
//致命错误:在第22行的\ src \ Exception \ ConfigException.php中找不到类'Akamai \ Open \ EdgeGrid \ Exception'require_once'src / Exception / SignerException / InvalidSignDataException.php';
//致命错误:在第22行的\ src \ Exception \ SignerException \ InvalidSignDataException.php中找不到类'Akamai \ Open \ EdgeGrid \ Exception \ SignerException'
答案 0 :(得分:0)
require
块中缺少两个例外:
require_once 'src/Exception.php';
require_once 'src/Exception/SignerException.php';
添加这些可以解决问题。
清除您的完整代码块将使用:
$auth = \Akamai\Open\EdgeGrid\Authentication::createFromEdgeRcFile('ccuv3', './.edgerc');
$auth->setHttpMethod('POST');
$auth->setPath('/ccu/v3/invalidate/url');
$body = json_encode(array(
'hostname' => 'example.org',
'objects' => array('/path/to/object', '/path/to/other/object')
));
$auth->setBody($body);
$context = array(
'http' => array(
'header' => array(
'Authorization: ' . $auth->createAuthHeader(),
'Content-Type: application/json',
'Content-Length: ' . strlen($body),
),
'method' => 'POST',
'content' => $body
)
);
$context = stream_context_create($context);
$response = json_decode(file_get_contents('https://' . $auth->getHost() . $auth->getPath(), null, $context));
更好的是,将它包含在一个函数中:
function fastPurge($hostname, array $objects)
{
$body = json_encode(array(
'hostname' => $hostname,
'objects' => $objects
));
$auth = \Akamai\Open\EdgeGrid\Authentication::createFromEdgeRcFile('ccuv3', './.edgerc');
$auth->setHttpMethod('POST');
$auth->setPath('/ccu/v3/invalidate/url');
$auth->setBody($body);
$context = array(
'http' => array(
'header' => array(
'Authorization: ' . $auth->createAuthHeader(),
'Content-Type: application/json',
'Content-Length: ' . strlen($body),
),
'method' => 'POST',
'content' => $body
)
);
$context = stream_context_create($context);
$response = json_decode(file_get_contents('https://' . $auth->getHost() . $auth->getPath(), null, $context));
}
// Call the fastPurge function
fastPurge('example.org', array('/path/to/object', '/path/to/other/object'));