What are the potential pitfalls of using file_get_contents for HTTP requests in PHP?

Potential pitfalls of using file_get_contents for HTTP requests in PHP include lack of error handling, limited control over request headers, and potential security vulnerabilities. To solve these issues, it is recommended to use the cURL extension in PHP, which provides more flexibility and control over HTTP requests.

$url = 'https://example.com/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

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

curl_close($ch);