我正在使用清除特定目录子目录缓存的函数。我正在将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);
}
}
}
答案 0 :(得分:1)