I have an image gallery that I'm putting together and I've got a script that is called from the administrative backend through exec(). It searches a "batch" folder for images I've uploaded in bulk for it to automatically add to the database. This process can take a few minutes depending on the number and size of images I've uploaded to said folder, being the reason it must be spawned externally like that. But I'd like to know if there's a feasible way to keep from accidentally running another instance of the script as this would surely cause conflicts if another batch process was already running. Ideally it should work like this: Go to Admin panel. Click on Batch Processing. Get a message stating it's currently processing and will be finished shortly. Go to Admin Panel again. See that Batch Processing is greyed out/unclickable to prevent spawning. If it is somehow spawned again, receive an error message another batch process is already running and refuse to run another until the first is finished. The simplest way I can figure to do this is make a plaintext "lock file" (maybe call it "batch_lock.txt") that simply contains 1 or 0 that the admin panel and the batch.php looks for. When batch.php is finished, it simply sets the number in the file to Zero so another can. Any suggestions are appreciated.
That's what I thought. What I might do is make the external script simply create a zero-byte "batch_lock" file when it runs and deletes it when it finishes. The mere presence of it should be enough. If some error occurs and the batch process is terminated prematurely, I would need a way to reset this lock file manually, just in case.