Do we need to close file_get_contents?

harishkumar329 picture harishkumar329 · Oct 29, 2013 · Viewed 7.9k times · Source

I'm running file_get_contents() inside a loop, I see a lot of files opened in the Apache log. I don't know the reason behind it. Do we need to close the file_get_contents() function after each read?

Answer

user1864610 picture user1864610 · Oct 29, 2013

file_get_contents() reads a file and closes the file afterwards. It returns the read data or false, so you have no file handle to use with an fclose(), anyway.