I have a PHP script that runs automatically from the CLI every day (using Task Scheduler on Windows) but may also be run manually via the browser. The script may conclude very quickly - within a matter of seconds, or may run for many hours (at which point it sends an email).
What I'd like to be able to do is have the script check to see if an instance of itself is already running - because if two (or more) instances are kicked off, then I'll have two (or more) emails when it completes.
Is it possible for a PHP script to save some kind of process id (for itself) to a file and continue executing, and then have another script read that file and use the process id to terminate the original instance?
I already have a log file generated every time the script runs. So I envision somehow being able to save a reference to the currently executing script to the top of that log. Then if the script is executed again, it can check the log to see if an instance of itself is already running and if so kill it?
I apologize if this isn't very clear - I'm having a tough time concisely articulating what I'm trying to do