Running a php script via ajax, but only if it is not already running

后端 未结 6 1621
轮回少年
轮回少年 2021-02-13 21:28

My intention is this.

My client.html calls a php script check.php via ajax. I want check.php to check if another script task.php is already being run. If it is, I do not

6条回答
  •  广开言路
    2021-02-13 21:50

    You can realize it, using lock file:

    if(is_file(__DIR__.'/work.lock'))
    {
        die('Script already run.');
    }
    else
    {
        file_put_contents(__DIR__.'/work.lock', '');
        // YOUR CODE
        unlink(__DIR__.'/work.lock');
    }
    

提交回复
热议问题