sony/cdn-purge-control-php
Composer 安装命令:
composer require sony/cdn-purge-control-php
包简介
CDN Purge Control SDK for PHP - Lightweight PHP library to control multiple CDN edge cache.
README 文档
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
| 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.
sony/cdn-purge-control-php 适用场景与选型建议
sony/cdn-purge-control-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.77k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cache」 「sdk」 「cloudfront」 「cdn」 「purge」 「limelight」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sony/cdn-purge-control-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sony/cdn-purge-control-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sony/cdn-purge-control-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
CloudFront cache purger for the Blitz plugin.
Amazon Web Services (AWS) Toolbox - This extension connects your TYPO3 instance to Amazon CloudFront. It rewrites all file paths in the frontend to match your CDN domain. You also have the possibility to invalidate Amazon CloudFront entries.
Laravel 5 - Repositories to the database layer
CDN Cache Control and Invalidation
Serve Laravel Assets from a Content Delivery Network (CDN)
统计信息
- 总下载量: 5.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-01-12