What are some common tools for making HTTP requests in PHP?

When working with HTTP requests in PHP, some common tools that can be used are cURL and the built-in functions like file_get_contents or fopen. These tools allow you to make requests to external APIs, fetch data from remote servers, or interact with web services.

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

// Using file_get_contents to make an HTTP GET request
$response = file_get_contents('https://api.example.com/data');

// Using fopen to make an HTTP GET request
$handle = fopen('https://api.example.com/data', 'r');
$response = stream_get_contents($handle);
fclose($handle);