Geen omschrijving

cdn_get_flux.php 831B

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