What are the advantages and disadvantages of using the file() function in PHP to make HTTP requests?

The file() function in PHP can be used to make HTTP requests, but it has limitations such as not being able to handle POST requests or custom headers. An alternative approach is to use the cURL library in PHP, which provides more flexibility and control over HTTP requests.

// Using cURL to make an HTTP GET request
$url = 'https://example.com/api';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Output the response
echo $response;