What’s the difference between curl and file_get_content?

file_get_content:


It is a function to get the contents of a file. file_get_contents() for a remote file, it is very slow, and does not handle redirects, caching, cookies. It is a function to get the contents of a file (simply view source items i.e out put html file contents).

example:

<?php
$output = file_get_contents(‘http://www.prafulkr.in/’);
echo $output;
?>

 

curl

It is a library.curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies. Curl is a much faster alternative to file_get_contents. It is a library to do more operations, for example get the contents like file_get_contents, sending and receiving data from one site to another site and it also supports different types of protocols like http, https, ftp, gopher, telnet, dict, file, and ldap. curl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.

example:

<?php
$url=’http://www.prafulkr.in/’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>

Posted in PHP | Tagged , , , , , | Comments Off

Comments are closed.