avoiding conflicts with php file_put_contents

93 Views Asked by At

I am logging visitor custom search queries to a text file as follows:

define('SEARCH_LOG', 'log.txt');
file_put_contents(SEARCH_LOG, "\n" . $search, FILE_USE_INCLUDE_PATH | FILE_APPEND);

Every 100 searches, I sort and collate the entries and email them to the site owner. Then I clear the file as follows:

file_put_contents(SEARCH_LOG, "", FILE_USE_INCLUDE_PATH);

I understand that file_put_contents is identical to calling fopen(), fwrite(), and fclose() successively.

  1. Do I need to worry about collisions between users or is this somehow handled for me?

  2. Do I need to write a conditional retry?

  3. Should I use the LOCK_EX flag?

0

There are 0 best solutions below