best way to obtain a lock in php

后端 未结 10 1118
甜味超标
甜味超标 2020-12-07 15:10

I\'m trying to update a variable in APC, and will be many processes trying to do that.

APC doesn\'t provide locking functionality, so I\'m considering using other me

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 15:30

    APC is now considered unmaintained and dead. It's successor APCu offers locking via apcu_entry. But be aware, that it also prohibits the concurrent execution of any other APCu functions. Depending on your use case, this might be OK for you.

    From the manual:

    Note: When control enters apcu_entry() the lock for the cache is acquired exclusively, it is released when control leaves apcu_entry(): In effect, this turns the body of generator into a critical section, disallowing two processes from executing the same code paths concurrently. In addition, it prohibits the concurrent execution of any other APCu functions, since they will acquire the same lock.

提交回复
热议问题