项目作者: sony

项目描述 :
Multi CDN purge control library for PHP
高级语言: PHP
项目地址: git://github.com/sony/cdn-purge-control-php.git
创建时间: 2016-01-06T01:41:28Z
项目社区:https://github.com/sony/cdn-purge-control-php

开源协议:MIT License

下载


CdnPurge, Multi CDN purge control library for PHP

Build Status
Stable Version
MIT license

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.

  1. # Install Composer
  2. curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version of CdnPurge:

  1. composer.phar require sony/cdn-purge-control-php

After installing, you need to require Composer’s autoloader:

  1. require 'vendor/autoload.php';

You can then later update CdnPurge using composer:

  1. composer.phar update

Quick Examples

Make purge request

  1. <?php
  2. // Require the Composer autoloader.
  3. require 'vendor/autoload.php';
  4. use CdnPurge\CdnPurgeFactory;
  5. use CdnPurge\CdnType;
  6. $config = array(
  7. 'cloudfront' => array(
  8. 'distribution_id' => 'your cloudfront distribution id'
  9. ),
  10. 'limelight' => array(
  11. 'shortname' => 'your limelight api shortname'
  12. 'publish_url' => 'your limelight publish url'
  13. )
  14. );
  15. $credential = array(
  16. 'cloudfront' => array(
  17. 'key' => 'aws iam account access key id',
  18. 'secret' => 'aws iam account secret access key'
  19. ),
  20. 'limelight' => array(
  21. 'username' => 'limelight account username',
  22. 'shared_key' => 'limelight account shared key'
  23. )
  24. );
  25. try {
  26. // Make a purge request against AWS cloudfront
  27. $cfClient = CdnPurgeFactory::build(CdnType::CLOUDFRONT, $credential, $config);
  28. $cfRequestId = $client->createPurgeRequest(array(
  29. '/my-path-1',
  30. '/my-path-2'
  31. ));
  32. // Make a purge request against Limelight
  33. $llClient = CdnPurgeFactory::build(CdnType::LIMELIGHT, $credential, $config);
  34. $llRequestId = $client->createPurgeRequest(array(
  35. 'http://my-limelight-domain/my-path-1',
  36. '/my-path-2'
  37. ));
  38. } catch (CdnPurge\CdnClientException $e) {
  39. echo "An error occurred: " . $e->getMessage();
  40. }

Get purge status

  1. <?php
  2. // Get the purge status
  3. try {
  4. $client->getPurgeStatus($requestId);
  5. // 'InProgress' or 'Complete'
  6. } catch (CdnPurge\CdnClientException $e) {
  7. echo "There was an error getting purge status.\n";
  8. }

See example for a running example of how to use this library.

Specifying credentials

Credentials are specified as an array.

AWS CloudFront

Credential key Type Required Description
cloudfront[‘key’] String Yes AWS IAM user Access Key Id. See here for details
cloudfront[‘secret’] String Yes AWS IAM user Secret Access Key. See here for details

Limelight

Credential key Type Required Description
limelight[‘username’] String Yes Limelight account username
limelight[‘shared_key’] String Yes Limelight account share key

Specifying configurations

Configurations are specified as an array.

AWS CloudFront

Config key Type Required Description
cloudfront[‘distribution_id’] String Yes AWS CloudFront Distribution Id
http[‘proxy’] String No Specify http proxy for the client. For example: ‘my-company.proxy.com:1234’

Limelight

Config key Type Required Description
limelight[‘shortname’] String Yes Limelight api shortname
limelight[‘publish_url’] String No Limelight publish url. This is prepended to the purge path if the path doesn’t start with ‘http’ or ‘https’
limelight[‘evict’] Boolean No If true, matching cache objects are evicted (deleted), otherwise invalidated. Default is false
limelight[‘exact’] Boolean No If true, paths to be purged are treated as an exact public URL. Optional. Default is false. Default is false
limelight[‘incqs’] Boolean No If true, pattern is allowed to match query string part of URL, otherwise query string is stripped before matching. Default is false
limelight[‘email’] Array No Array of email info to send purge completion details to
limelight[‘email’][‘subject’] String No Subject of sent mail
limelight[‘email’][‘to’] String Yes Email recipient address. A comma is used to separate multiple recipients
limelight[‘email’][‘cc’] String No Email carbon copy. A comma is used to separate multiple recipients
limelight[‘email’][‘bcc’] String No Email blind carbon copy. A comma is used to separate multiple recipients
limelight[‘callback’] Array No HTTP(S) callback URL for purge request state transition notifications
limelight[‘callback’][‘url’] String Yes Callback url
http[‘proxy’] String No Specify http proxy for the client. For example: ‘my-company.proxy.com:1234’

Development

License

The MIT License (MIT)

See LICENSE for details.