How to prevent PHP script running more than once?

前端 未结 6 916
臣服心动
臣服心动 2020-12-05 16:23

Currently, I tried to prevent an onlytask.php script from running more than once:

$fp = fopen(\"/tmp/\".\"onlyme.lock\", \"a+\");
if (flock($fp,         


        
6条回答
  •  余生分开走
    2020-12-05 16:55

    You can use lock files, as some have suggested, but what you are really looking for is the PHP Semaphore functions. These are kind of like file locks, but designed specifically for what you are doing, restricting access to shared resources.

提交回复
热议问题