Nenhuma descrição

cdn_refresh_urls_dirs.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. //---------------------------------------- demo1 ----------------------------------------
  10. // 刷新文件和目录
  11. // 文件列表一次最多提交 60 个,目录一次最多提交 10 个
  12. // 参考文档:https://developer.qiniu.com/fusion/api/1229/cache-refresh
  13. $urls = array(
  14. "http://phpsdk.qiniudn.com/qiniu.jpg",
  15. "http://phpsdk.qiniudn.com/qiniu2.jpg",
  16. );
  17. $dirs = array(
  18. "http://phpsdk.qiniudn.com/test/"
  19. );
  20. $cdnManager = new CdnManager($auth);
  21. // 如果刷新返回 400038 报错,则需要联系七牛技术支持开通刷新目录权限,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh,
  22. list($refreshResult, $refreshErr) = $cdnManager->refreshUrlsAndDirs($urls, $dirs);
  23. if ($refreshErr != null) {
  24. var_dump($refreshErr);
  25. } else {
  26. echo "refresh request sent\n";
  27. print_r($refreshResult);
  28. }
  29. //---------------------------------------- demo2 ----------------------------------------
  30. // 刷新文件
  31. list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls);
  32. if ($refreshErr != null) {
  33. var_dump($refreshErr);
  34. } else {
  35. echo "refresh urls request sent\n";
  36. print_r($refreshResult);
  37. }
  38. //---------------------------------------- demo3 ----------------------------------------
  39. // 刷新目录
  40. list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs);
  41. if ($refreshErr != null) {
  42. var_dump($refreshErr);
  43. } else {
  44. echo "refresh dirs request sent\n";
  45. print_r($refreshResult);
  46. }