What is better? I have my own MySQL log so it has about 90MB, but I'm not sure which one should I use. It opens file EVERYTIME there is query to execute.
What's faster?
fwrite() allows to write to file a byte or block of bytes at a time, file_put_content() writes the entire file in one go.... which is better? depends what you need to do! and on the volumes of data that you want to write! fwrite requires a handle while file_put_contents does not.
The file_put_contents() function returns the number of bytes that were written to the file, or FALSE on failure.
According to this article, the fwrite()
is a smidgen faster. (Link to Wayback Machine, because site no longer exists.)
My guess is that file_put_contents()
is just a wrapper around those three methods anyways, so you would lose the overhead.
EDIT : This site has the same information.
This function is identical to calling fopen(), fwrite() and fclose() successively to write data to a file.
Check the docs: http://php.net/manual/en/function.file-put-contents.php
Shaun
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With