cdn_get_flux.php 786 B

12345678910111213141516171819202122232425262728293031323334
  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($fluxData, $getFluxErr) = $cdnManager->getFluxData($domains, $startDate, $endDate, $granularity);
  20. if ($getFluxErr != null) {
  21. var_dump($getFluxErr);
  22. } else {
  23. echo "get flux data success\n";
  24. print_r($fluxData);
  25. }