conneredu300 / php-keycdn-api
KeyCDN API 的 PHP 库
dev-keycdn
2017-08-09 11:51 UTC
Requires
- php: >=5.3.0
- ext-curl: *
This package is not auto-updated.
Last update: 2024-09-19 03:19:14 UTC
README
KeyCDN API 的 PHP 库
KeyCDN 是一个用于加速您的网络资源的内容分发网络。
如果您有任何问题或需要更多功能,请联系我们: KeyCDN 支持
要求
- PHP 5.3 或更高版本
- PHP Curl 扩展
使用方法
<?php require 'path_to_repo/src/KeyCDN.php'; // create the REST object $keycdn_api = new KeyCDN('your_api_key'); // get zone information $keycdn_api->get('zones.json'); // change zone name and check if successfull $result = $keycdn_api->post('zones/123.json', array( 'name' => 'newzonename', )); // convert json-answer into an array $answer = json_decode($result, true); if ($answer['status'] == 'success') { echo 'Zonename successfully changed...'; }
获取流量统计信息
// get traffic stats for the last 30 days $result = $keycdn_api->get('reports/traffic.json', array( 'zone_id' => 123, 'start' => Carbon::now('UTC')->subDays(30)->timestamp, 'end' => Carbon::now('UTC')->timestamp )); // convert json-answer into an array $answer = json_decode($result, true); // since we get results pr day, we need to sum them if ($answer['status'] == 'success') { $amount = 0; foreach ($answer['data']['stats'] as $stats) { $amount += $stats['amount']; } echo 'Traffic last 30 days: ' . $amount; } else { echo 'Something went wrong...' }
单个或批量 URL 清理
$result = $keycdn->delete('zones/purgeurl/{zone_id}.json', array( 'urls' => array('foo-1.kxcdn.com/bar1.jpg','foo-1.kxcdn.com/bar2.jpg'), ));
方法
支持的所有 HTTP 方法(GET、PUT、POST、DELETE)在 KeyCDN 库中都有自己的函数生成。例如,POST 变为 $keycdn_api->post(...);
。