I have page on an intranet site to launch a long running PHP script on the server. The page has a button to start the long running process. Button calls a PHP script via Ajax which starts the process and PHP script returns a 200 code quickly to the Ajax caller. The PHP-initiated server process is dumping its progress to a file and the page reports the progress based on an Ajax loop. My issue is that I can have multiple users connecting to the page, but only one should be able to initiate the long running php script at one time while every other user should only see the progress updates (i.e. wait for the long process to finish). (Once the long process is done it can be launched again, but that's not really relevant here.)
I think this problem must be fairly standard - a single entry, block other requests while running a server process problem. My original idea is to create a lock file on the server on first entry and check the file's existence on consecutive entries to the script. I would clean up the lock file at the conclusion of the server processing.
Is this the "standard pattern" for this problem or it there a better one? Does PHP provide any built-in locking feature which could be used in this scenario?