etrader Posted September 13, 2011 Share Posted September 13, 2011 I want to load and display the content of a text file (actually it is a cache file). I tested both method using a long for loop as for ($i=0; $i < 10000; $i++) { $handle = fopen("test.txt", "r"); $text = fread($handle, filesize("test.txt")); fclose($handle); echo $text; } and for ($i=0; $i < 10000; $i++) { $text = file_get_contents("test.txt"); echo $text; } but the results were similar, though with a large distribution of the comparative data. The speed of a method was 0.5 to 2.0 faster than the other one (in various runs). Which method do you recommend? Could you please quote the pros and cons of each method? Quote Link to comment https://forums.phpfreaks.com/topic/247039-fread-vs-file_get_contents/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.