Synchronized functions using PHP

后端 未结 4 2103
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 02:04

How to make functions in PHP synchronized so that same function won\'t be executed concurrently ? 2nd user must wait till 1st user is done with the function. Then 2nd user

4条回答
  •  天涯浪人
    2020-12-11 02:50

    off the top of my head:

    • function checks if a database field called isFunctionRunning is equal 1. if not start executing
    • you update the database field called isFunctionRunning to 1
    • function does magic here
    • you update the database field called isFunctionRunning to 0

    but somehow i think what you are trying to do is "wrong" and can be achieved in another way. could help if you said more details

    edit: wasn't aware of php semaphores, the answer above will be way faster.

提交回复
热议问题