cdn_get_bandwidth.php 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. require_once __DIR__ . '/../autoload.php';
  3. use Qiniu\Auth;
  4. use Qiniu\Cdn\CdnManager;
  5. // 控制台获取密钥:https://portal.qiniu.com/user/key
  6. $accessKey = getenv('QINIU_ACCESS_KEY');
  7. $secretKey = getenv('QINIU_SECRET_KEY');
  8. $auth = new Auth($accessKey, $secretKey);
  9. $cdnManager = new CdnManager($auth);
  10. // 获取流量和带宽数据
  11. // 参考文档:https://developer.qiniu.com/fusion/api/1230/traffic-bandwidth
  12. $domains = array(
  13. "javasdk.qiniudn.com",
  14. "phpsdk.qiniudn.com"
  15. );
  16. $startDate = "2020-08-03";
  17. $endDate = "2020-08-05";
  18. // 5min or hour or day
  19. $granularity = "day";
  20. list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData(
  21. $domains,
  22. $startDate,
  23. $endDate,
  24. $granularity
  25. );
  26. if ($getBandwidthErr != null) {
  27. var_dump($getBandwidthErr);
  28. } else {
  29. echo "get bandwidth data success\n";
  30. print_r($bandwidthData);
  31. }