How to set cache control for curl in php

By | September 13, 2016

How to set cache control for curl in php

While using CURL to get connection and data from another server through api, sometimes we are opted with same data again and again. This is because may be the server is set to serve cache data for frequent request for a same api or url. We can easily overcome this issue by using the curl_setopt() function with the CURLOPT_FRESH_CONNECT option of curl request.

By default this option is set to false in a curl request. So we need to set this value to true in order to get fresh content (not cached one).

CURLOPT_FRESH_CONNECT =TRUE will force the use of a new connection instead of a cached one.

We can also do this by setting headers. To do this we need to set the cache-control to no-cache.

Hope you find this post helpful. Let me know if you have any doubt, through comments.

 

🔥0

Leave a Reply