function curl_header($url, $follow_redirect = true, $tmp_dir = null) { $info = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, 'Data.gov data.json crawler'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIE, ""); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_redirect); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); $http_heading = curl_exec($ch); $info['header'] = http_parse_headers($http_heading); $info['info'] = curl_getinfo($ch); curl_close($ch); // If the server didn't support HTTP HEAD, use the shim. if (!empty($info['header']['X-Error-Message']) && trim($info['header']['X-Error-Message']) == 'HEAD is not supported' or empty($info['header']['Content-Type'])) { return curl_head_shim($url, $follow_redirect, $tmp_dir); } else { return $info; } }
function curl_header($url, $follow_redirect = true, $tmp_dir = null) { $info = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, 'Data.gov data.json crawler'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_COOKIE, ""); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_redirect); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); if (config_item('proxy_host') && config_item('proxy_port')) { $proxy = config_item('proxy_host') . ":" . config_item('proxy_port'); curl_setopt($ch, CURLOPT_PROXY, $proxy); } $http_heading = curl_exec($ch); $info['header'] = http_parse_headers($http_heading); $info['info'] = curl_getinfo($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (!$httpCode) { error_log("curl_header return code for url {$url} is HTTP Status '0' \n" . curl_error($ch)); } curl_close($ch); // If the server didn't support HTTP HEAD, use the shim. if (!empty($info['header']['X-Error-Message']) && trim($info['header']['X-Error-Message']) == 'HEAD is not supported' or empty($info['header']['Content-Type']) && empty($info['header']['Content-type'])) { return curl_head_shim($url, $follow_redirect, $tmp_dir); } else { return $info; } }