How can PHP be used to check the loading time of an external URL?
To check the loading time of an external URL using PHP, you can use the curl_init() function to make a request to the URL and then measure the time it takes to receive a response. This can be achieved by recording the start time before making the request and then calculating the difference in time after receiving the response.
$url = 'https://www.example.com';
$start_time = microtime(true);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$end_time = microtime(true);
$total_time = $end_time - $start_time;
echo "The loading time of $url is: " . $total_time . " seconds";
curl_close($ch);