Which is faster in PHP:
echo file_get_contents('http://example.com/file.txt');
or
$file = file_get_contents('http://example.com/file.txt'); echo $file;
I am using server side includes (require('/var/www/menu.php');) for my menus etc but want to use this for certain things (eg on other domains)
Thanks
If you use this method hugely on everypage for very large files, then you would waste memory space by extra variables. so the better approach would be:
It would be a better question to ask which function is faster file_get_contents() or fread()? Then the answer was if file is more than 1MB or 2MB then use file_get_contents() which can perform better.
You can see a benchmark here:
Large file was 2.3MB and the small one was about 3.0KB.
I ran both functions against small files 100,000 times and ran it again on large file just once.