I’m writing a simple caching plugin for our site and I’d like to use CURL to preload the cache. If I access the system via a browser, the caching works fine. But my CURL requests are not being cached. I have provided the details of my trials on stack overflow, but I’ll repeat some of them here:
One.php makes two separate CURL requests to two.php . I want Cloudflare to cache the first response, and to serve that cache in the second response. But for some reason, Cloudflare is not caching either response. If I then visit two.php using my browser, it’s still not cached. If I then refresh two.php in my browser, I finally receive a cache HIT. How do I trigger caching on Couldflare via CURL requests?
Bare Bones Test:
header("Cache-Control: no-store"); $url = "http://www.example.com/two.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_exec($ch); // prints current timestamp, see two.php curl_close($ch); sleep(1); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_exec($ch); // prints current timestamp, see two.php curl_close($ch);
header( 'Cache-Control: public, max-age=10' ); print( time()."<br>\r\n" );