Read and write to a file while keeping lock

前端 未结 3 693
半阙折子戏
半阙折子戏 2020-12-03 22:10

I am making a simple page load counter by storing the current count in a file. This is how I want to do this:

  1. Lock the file (flock)
  2. Read the current c
3条回答
  •  被撕碎了的回忆
    2020-12-03 22:20

    I believe you can achieve this using flock. Open a pointer to your file, flock it, read the data, write the data, then close (close automatically unlocks).

    http://php.net/flock

提交回复
热议问题