cdn_get_bandwidth.php 840 B

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