Reputation: 7693
I was wondering what's the technical difference between these two:
error_log('test', 3, 'test.txt');
versus
file_put_contents('test.txt', 'test', FILE_APPEND);
They both seem to take the same amount of time, however.
Upvotes: 3
Views: 1471
Reputation: 4278
Specifically between error_log('test', 3, 'test.txt')
and file_put_contents('test.txt', 'test', FILE_APPEND)
there is no difference by what the documentation says (file_put_contents and error_log) as both will just append it to a file.
The main difference between the functions is that error_log
can do more than log to a file with the ability to send to PHP's system logger, send the error as email or send it to the SAPI logging handler if you set either 0
, 1
or 4
.
Using file_put_contents
does allowing specifying a string, array or stream resource whereas error_log
only allows specifying a string as the message. This may have an impact depending what data you are wanting to log however your example is just a string so it doesn't hold any importance.
If, like in your example, you are writing a simple string error message to a file they will have the same end result. With that said though, I would recommend using error_log
as it allows easier conversion later on to sending email messages and the function name better suits its task for future maintainers of the code.
If you are not intending to use it as for writing an error message (and I only say this because of the choice of words in the question title - "When storing data..." vs "When storing errors..."), I would recommend using file_put_contents
for a similar reason in my paragraph above in that the function name better suits its task for future code maintainers.
Upvotes: 3