In what scenarios should URLs be formatted correctly with protocols like http:// or https:// when using PHP functions like Readfile?

When using PHP functions like Readfile to read files from URLs, it is important to ensure that the URLs are correctly formatted with protocols like http:// or https://. This is necessary for the function to properly retrieve the file from the remote server. Failure to include the protocol in the URL can result in errors or the function not working as expected.

$url = 'https://example.com/file.txt';
readfile($url);