How can I use file_put_contents() with FILE_APPEND | LOCK_EX safety?

前端 未结 2 2218
借酒劲吻你
借酒劲吻你 2021-02-19 11:07

I\'m using:

file_put_contents(\"peopleList.txt\", $person, FILE_APPEND | LOCK_EX);

to write to the end of a file and to make sure no one else (

2条回答
  •  走了就别回头了
    2021-02-19 12:01

    If the function fails to get the lock for the file then it will return an error you can use.

    if ($result === false) { print "failed to lock"; }
    

    Now if you want to try to get a the lock a few times just use a loop to keep trying to write to the file.

提交回复
热议问题