CURL file_get_contents alternative

CURL is faster than file_get_contents so this is much better to use


function file_get_contents_curl($url) {
	$ch = curl_init();
	
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
	curl_setopt($ch, CURLOPT_URL, $url);
	
	$data = curl_exec($ch);
	curl_close($ch);
	
	return $data;
}

//how to use
$var = file_get_contents_curl("http://www.google.com");

Associated Files

Comments

Log in to comment