Skip to content

Instantly share code, notes, and snippets.

@jonathan-bird
Last active October 31, 2016 00:19
Show Gist options
  • Save jonathan-bird/90b5f555ccc74f3eec5dc2e25d9411ac to your computer and use it in GitHub Desktop.
Save jonathan-bird/90b5f555ccc74f3eec5dc2e25d9411ac to your computer and use it in GitHub Desktop.
Imgix API Image Purge with Guzzle 5
<?php
use Guzzle\Http\Client;
use Guzzle\Http\Exception\ClientErrorResponseException;
private function purgeImgixCache($imageUrl)
{
$client = new Client();
try {
$request = $client->post('https://api.imgix.com/v2/image/purger',
[
'Content-Type' => 'application/json',
'Authorization' => 'Basic ' . base64_encode('THIS_IS_API_KEY_STRING' . ':')
],
[
'url' => $imageUrl
]
);
$response = $request->send();
} catch (ClientErrorResponseException $exception) {
$responseBody = $exception->getResponse()->getBody(true);
return false;
}
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment