【问题标题】:Purge cache subdirectories Cloudflare清除缓存子目录 Cloudflare
【发布时间】:2019-04-30 00:36:21
【问题描述】:

我正在开发一个清除特定目录的子目录缓存的功能。我在我的服务器上使用 cloudflare 如果有人有想法 这是我的作文

<?php
class Custom_Tools_Cflare
{
    public function clear($dir,$host,$uri) {
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/xxxxxxxxxx/purge_cache");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"files\":[\"http://xxxx.com/".$dir."/".$uri."\",{\"url\":\"http://xxxx.com/".$dir."/".$uri."\",\"headers\":{\"X-Forwarded-Host\":\"".$host."\",\"X-Host\":\"xxxxxxx.com\"}}]}");
        curl_setopt($ch, CURLOPT_POST, 1);

        $headers = array();
        $headers[] = "X-Auth-Email: xxxx@xxxx.com";
        $headers[] = "X-Auth-Key: xxxxxxxxxxx";
        $headers[] = "Content-Type: application/json";
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        $result = curl_exec($ch);
        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
        }
        curl_close ($ch);
    }
    public function myfunction(){

        $di = new RecursiveDirectoryIterator('http://xxxxx.com/');
        foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
        $file->clear($di,$host,$uri);
        }
    }
}

【问题讨论】:

    标签: php cloudflare


    【解决方案1】:

    您可以使用我编写的名为 purge-cloudflare-cache 的模块清除子目录缓存:

    答案就在这里:

    clearing cloudflare cache programmatically

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 2017-07-16
      • 2017-04-28
      相关资源
      最近更新 更多