Sending GET Request using PHP

To make an HTTP GET request with PHP, you can use the PHP-Curl library or the built-in PHP streaming functions. The Curl-based method is preferred when you need to send additional HTTP headers to the server with your GET request, limit download speed, or diagnose request errors, while PHP's built-in streaming functions are less verbose and easier to use. In this PHP GET Request Example, we send a GET request using the PHP-Curl library. The Curl-less method is provided below with detailed descriptions. Click Execute to run the PHP GET Request Example online and see the result.
Sending GET Request using PHP Execute
$url = "";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$resp = curl_exec($curl);

echo $resp;

Updated: Viewed: 2577 times

How to send a GET request using PHP streaming functions?

The PHP-Curl library is very powerful, but requires additional code to initialize and execute the request. If your GET request does not require additional functionality provided by PHP-Curl library, such as diagnosing request errors, viewing server response headers, or limiting the download speed, then you can use the PHP streaming function instead of the PHP-Curl library, which is easier to use.

PHP GET request with PHP streaming functions
$url = "";

$json = file_get_contents($url);

echo $json;

#output: {"success":"true"}