1. Go to this page and download the library: Download utopia-php/cdn library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
utopia-php / cdn example snippets
use Utopia\Cdn\Cache;
use Utopia\Cdn\Cache\Adapter\Cloudflare;
$cache = new Cache(new Cloudflare(
zoneId: 'YOUR_ZONE_ID',
apiToken: 'YOUR_API_TOKEN'
));
$cache->purgePaths('example.com', [
'/files/hero.png',
'/files/logo.svg',
]);
$cache->purgeDomain('example.com');
$cache->purgeKeys([
'host-deadbeef',
'deployment-12345',
]);
use Utopia\Cdn\Cache;
use Utopia\Cdn\Cache\Adapter\Fastly;
$cache = new Cache(new Fastly(
apiToken: 'YOUR_API_TOKEN',
domainKeyPrefix: 'domain-',
serviceId: 'YOUR_SERVICE_ID',
softPurge: false
));
$cache->purgePaths('example.com', [
'/files/hero.png',
'/files/logo.svg',
]);
// Purges the surrogate key "domain-example.com".
$cache->purgeDomain('example.com');
$cache->purgeKeys([
'host-deadbeef',
'deployment-12345',
]);
use Utopia\Balancer\Algorithm\First;
use Utopia\Balancer\Balancer;
use Utopia\Cdn\Cache;
use Utopia\Cdn\Cache\Adapter\Balancer as BalancerAdapter;
use Utopia\Cdn\Extend\CdnOption;
// $fastlyEdge, $fastlyRun and $cloudflare are adapters built as shown above.
$balancer = (new Balancer(new First()))
->addOption(new CdnOption($fastlyEdge, CdnOption::PROVIDER_FASTLY, edge: true))
->addOption(new CdnOption($fastlyRun, CdnOption::PROVIDER_FASTLY))
->addOption(new CdnOption($cloudflare, CdnOption::PROVIDER_CLOUDFLARE));
// Custom domains are cached by the run service and by Cloudflare, so purge both.
$balancer->addFilter(fn (CdnOption $option): bool => !$option->isEdge());
$cache = new Cache(new BalancerAdapter($balancer));
// One call, two providers: a Fastly surrogate key purge and a Cloudflare cache-tag purge.
$cache->purgeKeys(['domain-customer.example.com']);