Bunny CDN Purge
Author: Kev Quirk |
Hooks:
on_post_published on_post_updated on_post_deleted on_page_published on_page_updated on_page_deleted
Automatically purges your Bunny CDN pull zone cache when content changes, so visitors always see the latest version of your site.
Setup
Add your Bunny CDN access key and pull zone ID to the top of the function, then add the hook functions you need to your config/hooks.php.
⚠️ If your site's source code is publicly available, make sure your Bunny API key and Zone ID aren't.
function bunny_purge(): void
{
$accessKey = 'YOUR-ACCESS-KEY';
$pullZoneId = 'YOUR-PULL-ZONE-ID';
$ch = curl_init("https://api.bunny.net/pullzone/{$pullZoneId}/purgeCache");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["AccessKey: {$accessKey}"],
]);
curl_exec($ch);
}
function on_post_published(string $slug): void { bunny_purge(); }
function on_post_updated(string $slug): void { bunny_purge(); }
function on_post_deleted(string $slug): void { bunny_purge(); }
function on_page_published(string $slug): void { bunny_purge(); }
function on_page_updated(string $slug): void { bunny_purge(); }
function on_page_deleted(string $slug): void { bunny_purge(); }