title: Header only retrieval in php via curl
body: <p>Actually I have two questions.</p>
  
  <p>(1) Is there any reduction in <em>processing power</em> or <em>bandwidth</em> used on remote server if I retrieve only headers as opposed to full page retrieval using php and curl?</p>
  
  <p>(2) Since I think, and I might be wrong, that answer to first questions is <em>YES</em>, I am trying to get last modified date or If-Modified-Since header of remote file only in order to compare it with time-date of locally stored data, so I can, in case it has been changed, store it locally. However, my script seems unable to fetch that piece of info, I get <code>NULL</code>, when I run this:</p>
  
  <pre><code>class last_change {
  
   public last_change;
  
   function set_last_change() {
    $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, "http://url/file.xml");
      curl_setopt($curl, CURLOPT_HEADER, true);
      curl_setopt($curl, CURLOPT_FILETIME, true);
      curl_setopt($curl, CURLOPT_NOBODY, true);
    // $header = curl_exec($curl);
    $this -&gt; last_change = curl_getinfo($header);
    curl_close($curl);
   }
  
   function get_last_change() {
    return $this -&gt; last_change['datetime']; // I have tested with Last-Modified &amp; If-Modified-Since to no avail
   }
  
  }
  </code></pre>
  
  <p>In case <code>$header = curl_exec($curl)</code> is uncomented, header data is displayed, even if I haven't requested it and is as follows:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Fri, 04 Sep 2009 12:15:51 GMT
  Server: Apache/2.2.8 (Linux/SUSE)
  Last-Modified: Thu, 03 Sep 2009 12:46:54 GMT
  ETag: "198054-118c-472abc735ab80"
  Accept-Ranges: bytes
  Content-Length: 4492
  Content-Type: text/xml
  </code></pre>
  
  <p>Based on that, 'Last-Modified' is returned.</p>
  
  <p>So, what am I doing wrong?</p>