cdn_refresh_urls_dirs.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. //待刷新的文件列表和目录,文件列表最多一次100个,目录最多一次10个
  8. //参考文档:http://developer.qiniu.com/article/fusion/api/refresh.html
  9. $urls = array(
  10. "http://phpsdk.qiniudn.com/qiniu.jpg",
  11. "http://phpsdk.qiniudn.com/qiniu2.jpg",
  12. );
  13. //刷新目录需要联系七牛技术支持开通账户权限
  14. $dirs = array(
  15. "http://phpsdk.qiniudn.com/test/"
  16. );
  17. $cdnManager = new CdnManager($auth);
  18. // 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh
  19. // 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category
  20. list($refreshResult, $refreshErr) = $cdnManager->refreshUrlsAndDirs($urls, $dirs);
  21. if ($refreshErr != null) {
  22. var_dump($refreshErr);
  23. } else {
  24. echo "refresh request sent\n";
  25. print_r($refreshResult);
  26. }
  27. //如果只有刷新链接或者目录的需求,可以分布使用
  28. list($refreshResult, $refreshErr) = $cdnManager->refreshUrls($urls);
  29. if ($refreshErr != null) {
  30. var_dump($refreshErr);
  31. } else {
  32. echo "refresh request sent\n";
  33. print_r($refreshResult);
  34. }
  35. list($refreshResult, $refreshErr) = $cdnManager->refreshDirs($dirs);
  36. if ($refreshErr != null) {
  37. var_dump($refreshErr);
  38. } else {
  39. echo "refresh request sent\n";
  40. print_r($refreshResult);
  41. }