Search code examples
phpcurlcache-control

How to get cache-control max-age value from cUrl in PHP?


How to get cache-control: max-age value from cURL in PHP?

I have:

$this->get_headers_from_curl_response(curl_exec($this->curl));

Is there a parameter to cURL that would return only max-age value?


Solution

  • To make it very simple (not tested, but should work):

    $headers = $this->get_headers_from_curl_response(curl_exec($this->curl));
    $headers = explode("max-age=", $headers);
    $headers = explode("\n", $headers[1]);
    
    $max_age = trim($headers[0]);