コード例 #1
0
ファイル: httpclient.php プロジェクト: pneff/binarypool
 /**
  * Prepare a curl handle for the http request
  *
  * @param String $url the URL to fetch
  * @param int $modified (optional) seconds since Unix epoch of local copy
  * @return $curl curl handle
  */
 protected function prepareCurl($url, $lastmodified = 0)
 {
     $curl = curl_init();
     // See http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_USERAGENT, binarypool_config::getUseragent());
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     // return data as string
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
     // don't follow redirects
     curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
     // can't connect? fail fast...
     curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
     // total timeout
     curl_setopt($curl, CURLOPT_NOSIGNAL, true);
     curl_setopt($curl, CURLOPT_DNS_USE_GLOBAL_CACHE, FALSE);
     curl_setopt($curl, CURLOPT_FILETIME, TRUE);
     curl_setopt($curl, CURLOPT_HEADER, TRUE);
     curl_setopt($curl, CURLOPT_ENCODING, '');
     // sends Accept-Encoding for all suported encodings
     if ($lastmodified) {
         curl_setopt($curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
         curl_setopt($curl, CURLOPT_TIMEVALUE, $lastmodified);
     }
     return $curl;
 }