Is there a risk in running file_put_contents() on the same file from different PHP threads?

后端 未结 2 860
忘掉有多难
忘掉有多难 2020-12-09 08:23

I know file_put_contents() makes it really easy to append data to a file in PHP. I\'d like to try using PHP \"threads\" to file_put_contents() to the same log f

2条回答
  •  时光说笑
    2020-12-09 09:03

    as it says on the man page (that you gave a link for!):

    // Write the contents to the file, 
    // using the FILE_APPEND flag to append the content to the end of the file
    // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
    file_put_contents($file, $person, FILE_APPEND | LOCK_EX);
    

    Use the LOCK_EX flag to prevent double writes

提交回复
热议问题