sony / cdn-purge-control-php
CDN Purge Control SDK for PHP - Lightweight PHP library to control multiple CDN edge cache.
Installs: 5 759
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 15
Forks: 4
Open Issues: 1
Requires
- php: >=5.5
- aws/aws-sdk-php: ^3.8
- guzzlehttp/guzzle: ^6.1
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-09 18:59:27 UTC
README
CdnPurge is a lightweight PHP CDN client which makes it easier to purge contents for multiple CDN providers. Currently, CdnPurge supports AWS CloudFront and Limelight.
- Simple common interface to purge contents against multiple CDNs and get purge status.
- Easily extensible to other CDN providers.
- Easy code maintenance.
- Requires PHP >= 5.5 compiled with cURL extension and cURL 7.16.2+ compiled with a TLS backend (e.g. NSS or OpenSSL).
- Uses Guzzle to make http rest api calls.
Installing CdnPurge
The recommended way to install CdnPurge is through Composer.
# Install Composer curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of CdnPurge:
composer.phar require sony/cdn-purge-control-php
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
You can then later update CdnPurge using composer:
composer.phar update
Quick Examples
Make purge request
<?php // Require the Composer autoloader. require 'vendor/autoload.php'; use CdnPurge\CdnPurgeFactory; use CdnPurge\CdnType; $config = array( 'cloudfront' => array( 'distribution_id' => 'your cloudfront distribution id' ), 'limelight' => array( 'shortname' => 'your limelight api shortname' 'publish_url' => 'your limelight publish url' ) ); $credential = array( 'cloudfront' => array( 'key' => 'aws iam account access key id', 'secret' => 'aws iam account secret access key' ), 'limelight' => array( 'username' => 'limelight account username', 'shared_key' => 'limelight account shared key' ) ); try { // Make a purge request against AWS cloudfront $cfClient = CdnPurgeFactory::build(CdnType::CLOUDFRONT, $credential, $config); $cfRequestId = $client->createPurgeRequest(array( '/my-path-1', '/my-path-2' )); // Make a purge request against Limelight $llClient = CdnPurgeFactory::build(CdnType::LIMELIGHT, $credential, $config); $llRequestId = $client->createPurgeRequest(array( 'http://my-limelight-domain/my-path-1', '/my-path-2' )); } catch (CdnPurge\CdnClientException $e) { echo "An error occurred: " . $e->getMessage(); }
Get purge status
<?php // Get the purge status try { $client->getPurgeStatus($requestId); // 'InProgress' or 'Complete' } catch (CdnPurge\CdnClientException $e) { echo "There was an error getting purge status.\n"; }
See example for a running example of how to use this library.
Specifying credentials
Credentials are specified as an array.
AWS CloudFront
Limelight
Specifying configurations
Configurations are specified as an array.
AWS CloudFront
Limelight
Development
License
The MIT License (MIT)
See LICENSE for details.