2016-09-13 1 views
0

Wie Akamai Cache mit PHP 5.3 zu löschen?
Der Code in Akamai Github für PHP 5.6 + funktioniert. Aber der Code in Akamai Github Seite für PHP 5.3 gibt einen Fehler.Akamai schnelle Säuberung mit PHP 5.3

Die Fehler Linien markiert sind, als ‚//‘:

require_once 'src/Authentication.php';
require_once 'src/Authentication/Timestamp.php';
require_once 'src/Authentication/Nonce.php';
require_once 'src/Exception/ConfigException.php';
//Fatal error: Class 'Akamai\Open\EdgeGrid\Exception' not found in \src\Exception\ConfigException.php on line 22 require_once 'src/Exception/SignerException/InvalidSignDataException.php'‌​;
//Fatal error: Class 'Akamai\Open\EdgeGrid\Exception\SignerException' not found in \src\Exception\SignerException\InvalidSignDataException.php on line 22

+0

Welche Fehler? Bitte zeigen Sie Ihren Code. – Barmar

+0

Die Fehlerzeilen sind als '//' markiert 'require_once 'src/Authentication.php'; require_once 'src/Authentifizierung/Zeitstempel.php'; require_once 'src/Authentifizierung/Nonce.php'; require_once 'src/Exception/ConfigException.php'; // Schwerwiegender Fehler: Klasse 'Akamai \ Open \ EdgeGrid \ Exception' nicht in \ src \ Exception \ ConfigException.php in Zeile 22 gefunden require_once 'src/Exception/SignerException/InvalidSignDataException.php'; // Schwerwiegender Fehler: Klasse 'Akamai \ Öffnen \ EdgeGrid \ Exception \ SignerException' in \ src \ Exception \ SignerException \ InvalidSignDataException.php in Zeile 22 nicht gefunden – modellita

+1

Setzen Sie die Details in die Frage. – Barmar

Antwort

0

Es gibt zwei Ausnahmen von der require Block fehlt:

require_once 'src/Exception.php'; 
require_once 'src/Exception/SignerException.php'; 

diese Hinzufügen sollte das Problem beheben.

Der vollständige Codeblock spülen Sie verwenden würden:

$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)); 

Noch besser wäre es, dies in einer Funktion einpacken wäre:

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')); 
+0

Ja, der Fehler war weg. Was ist der nächste Schritt? – modellita

+0

@modellita Ich habe die Antwort aktualisiert, um den vollständigen CCUv3-Schnellbeseitigungsruf einzuschließen. –