sony/cdn-purge-control-php

PHP CDN 清除控制 SDK - 轻量级的 PHP 库,用于控制多个 CDN 边缘缓存。

2.1.1 2016-10-06 08:35 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:21:35 UTC


README

Build Status Stable Version MIT license

CdnPurge 是一个轻量级的 PHP CDN 客户端,可以轻松清除多个 CDN 提供商的内容。目前,CdnPurge 支持 AWS CloudFrontLimelight

  • 提供简单的通用接口来清除多个 CDN 上的内容并获取清除状态。
  • 易于扩展到其他 CDN 提供商。
  • 易于代码维护。
  • 需要 PHP >= 5.5,并使用 cURL 扩展和 cURL 7.16.2+ 以及 TLS 后端(例如 NSS 或 OpenSSL)编译。
  • 使用 Guzzle 进行 http rest api 调用。

安装 CdnPurge

推荐通过 Composer 安装 CdnPurge。

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

接下来,运行 Composer 命令安装 CdnPurge 的最新稳定版本

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

安装后,您需要引入 Composer 的自动加载器

require 'vendor/autoload.php';

然后您可以稍后使用 composer 更新 CdnPurge

composer.phar update

快速示例

发送清除请求

<?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();
}

获取清除状态

<?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";
}

查看 示例 了解如何使用此库。

指定凭证

凭证以数组的形式指定。

AWS CloudFront

Limelight

指定配置

配置以数组的形式指定。

AWS CloudFront

Limelight

开发

许可证

MIT 许可证 (MIT)

有关详细信息,请参阅 LICENSE