cdn_refresh_urls_dirs.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }