"Is it wise to use flock() or LOCK_EX in the file_put_contents call?"
is a good decision to use it. i also like to use designated folders for users and other objects whenever feasible so that their are no occurrences of two+ users ever writing to the same files. you could also do this for things like comment threads on an object and recursively construct the thread along with periodic/random cache file creation with logic to check time modified (file system data or file metadata) to determine which data to serve (and post-processes for cache updating) etc etc.