Tuesday, March 26, 2013

Logging revisited

If you're logging to a file - but of course you're logging to a database aren't you!? - but, if you are logging to a file, it's PHP so of course, there's a function for that:
file_put_contents($file, $data, FILE_APPEND|LOCK_EX)
From the manpage:
This function is identical to calling fopen(3), fwrite(3) and fclose(3) successively to write data to a file.

And of course, add the LOCK_EX only if you care about not corrupting your logfiles!

Enjoy! :)

No comments:

Post a Comment