How to make delete api call to cloudflare without CURL in PHP?
My hosting provider doesn't provide me Curl service
I am especially interested and wanna make php api call to CloudFlare to Purge All files from cache.
On api page I found
Then did research and research still research and found a way (maybe) by doing
<?php
$data = array (
"purge_everything" => true
);
$url = "https://api.cloudflare.com/client/v4/zones/MYZONEID/purge_cache";
$opts = array('http' =>
array(
'method' => 'DELETE',
'header' => "Content-Type: application/json\r\n" . "X-Auth-Key: MYKEY\r\n" . "X-Auth-Email: MYEMAIL\r\n",
'data' => json_encode($data)
)
);
$context = stream_context_create($opts);
$fp = @fopen($url, 'rb', false, $context);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
But got error on this
Fatal error: Uncaught Exception: Problem with https://api.cloudflare.com/client/v4/zones/MYZONEID/purge_cache, in /srv/disk11/2444530/www/xxxx.pl/test.php:16 Stack trace: #0 {main} thrown in /srv/disk11/2444530/www/xxxx.pl/test.php on line 16
I tried also this way:
<?php
$data = array (
"purge_everything" => true
);
$method = "getCallDetails";
$url = "https://api.cloudflare.com/client/v4/zones/MYZONEID/purge_cache";
$opts = array('http' =>
array(
'method' => 'DELETE',
'header' => "Content-Type: application/json\r\n" . "X-Auth-Key: MyKEY\r\n" . "X-Auth-Email: myEMAIL\r\n",
'data' => json_encode($data)
)
);
$context = stream_context_create($opts);
$result = file_get_contents($url, false, $context);
return $result;
But good also error, this time:
Warning: file_get_contents(https://api.cloudflare.com/client/v4/zones/MYAPIID/purge_cache): failed to open stream: Network is unreachable in /srv/disk11/2444530/www/xxxx.pl/test.php on line 15
And when I get on browser to my https://api.cloudflare.com/client/v4/zones/MYAPIID/purge_cache
i see
Reachable but doesn't work, something is bad here or it is even not possible at all.
So is it event possible to make this thing without CURL? And If yes how to do that?