} public function getQueue() { $response = $this->client->get('/ccu/v2/queues/default'); printf("The queue currently has %s items in it\n", json_decode($response->getBody())->queueLength); } public function checkProgress($resource) { $response = $this->client->get($resource); return json_decode($response->getBody()); } public function postPurgeRequest() { $purge_body = ["objects" => ["https://developer.akamai.com/stuff/Akamai_Time_Reference/AkamaiTimeReference.html"]]; printf("Adding %s to queue\n", json_encode($purge_body, JSON_UNESCAPED_SLASHES)); $response = $this->client->post('/ccu/v2/queues/default', ['body' => json_encode($purge_body), 'headers' => ['Content-Type' => 'application/json']]); return $response; } } $ccu = new CcuClient(); try { $ccu->getQueue(); $purge = $ccu->postPurgeRequest(); $progress = $ccu->checkProgress(json_decode($purge->getBody())->progressUri); $seconds_to_wait = $progress->pingAfterSeconds; printf("You should wait %s seconds before checking queue again...\n", $seconds_to_wait); } catch (\GuzzleHttp\Exception\ClientException $e) { // Handle errors echo "An error occurred: " . $e->getMessage() . "\n"; echo "Please try again with --debug or --verbose flags.\n"; }
namespace Akamai\Open\Example; require_once __DIR__ . '/cli/init.php'; class CcuClient { /** * @var \Akamai\Open\EdgeGrid\Client */ protected $client; public function __construct() { $this->client = \Akamai\Open\EdgeGrid\Client::createFromEdgeRcFile('ccuv3'); } public function postPurgeRequest($hostname, $objects) { $purge_body = ['hostname' => $hostname, 'objects' => $objects]; $response = $this->client->post('/ccu/v3/invalidate/url', ['body' => json_encode($purge_body), 'headers' => ['Content-Type' => 'application/json']]); return $response; } } $ccu = new CcuClient(); try { $objects = ["/index.html", "/image.jpg"]; $purge = $ccu->postPurgeRequest('akamaiapibootcamp.com', $objects); $response = json_decode($purge->getBody()); echo 'Success (' . $purge->getStatusCode() . ')' . PHP_EOL; echo 'Estimated Purge Time: ' . $response->estimatedSeconds . 's' . PHP_EOL; } catch (\GuzzleHttp\Exception\ClientException $e) { echo "An error occurred: " . $e->getMessage() . "\n"; echo "Please try again with --debug or --verbose flags.\n"; }