【问题标题】:How to make php api call to CloudFlare to Purge individual files by URL from cache如何使 php api 调用 CloudFlare 以通过 URL 从缓存中清除单个文件
【发布时间】:2018-07-03 07:45:19
【问题描述】:

这段代码可以很好地清除缓存中的所有文件。

例子:

$authKey = "MyKEY";
$authEmail = "myEMAIL";

$zoneId = "MYZONEID";
$endpoint = "purge_cache";

$data = [
    "purge_everything" => true
];

$url = "https://api.cloudflare.com/client/v4/zones/{$zoneId}/{$endpoint}";
$opts = ['http' => [
    'method' => 'DELETE',
    'header' => [
        "Content-Type: application/json",
        "X-Auth-Key: {$authKey}",
        "X-Auth-Email: {$authEmail}",
    ],
    'content' => json_encode($data),
]];
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);

但我需要通过 URL 清除单个文件,我如何通过 PHP 做到这一点?

在 api 页面上我找到了这个链接:https://api.cloudflare.com/#zone-purge-individual-files-by-url

但我现在不知道如何通过 php 制作它?

【问题讨论】:

    标签: api cloudflare purge


    【解决方案1】:

    您需要传递一个包含文件的数组 - 如 API Docs 中所述

    在你的例子中会是这样的

    $data = '{"files":[
      "http://www.example.com/css/styles1.css",
      "http://www.example.com/css/styles2.css",
      "http://www.example.com/css/styles3.css"
    ]}';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-28
      • 2017-07-16
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      相关资源
      最近更新 更多