Difference between curl and file_get_contents


In this tutorial,I will explain difference between curl and file_get_contents.
PHP offers two main options to get a remote file, curl and file_get_contents. There are many difference between the two.
file_get_contents - It is a function to get the contents of a file
curl - It is a library.curl supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies.
file_get_contents() for a remote file, it is very slow, and does not handle redirects, caching, cookies.
Curl is a much faster alternative to file_get_contents.
Using Curl:
<?php
$url='http://www.example.com/';
$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;
}
?>
Using file_get_contents:
<?php
$output = file_get_contents('http://www.example.com/');
echo $output;
?>