Search code examples
phpfopen

Does the PHP fopen() "a" mode need file locking?


I vaguely remember years ago someone saying that the a mode in the PHP fopen() call doesn't file locking - is this true?


Solution

  • The documentation does not mention anything about locking.

    However, there are some references about the flock function. This function is to be called after fopen as it takes a stream handle as parameter.

    It allows to acquire an exclusive lock, or a shared lock. It can also be released manually or automatically when calling fclose on locked resource, or when the said resource is garbage collected.