What are the limitations of file_get_contents when compared to cURL for handling HTTP requests in PHP?

file_get_contents has limitations when it comes to handling HTTP requests in PHP, such as not supporting custom headers or handling redirects as effectively as cURL. To overcome these limitations, you can use cURL in PHP, which provides more flexibility and control over HTTP requests.

// Using cURL to handle HTTP requests in PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Authorization: Bearer token'
));

$response = curl_exec($ch);

if($response === false){
    echo 'cURL error: ' . curl_error($ch);
}

curl_close($ch);

echo $response;