Hello, actually I want to write a demon - a script, working permanently, so I intend to use cron to launch a PHP script every minute and if that script is already running, die. But I don't know how to get informed if the script is running, I don't like the variant with creating and deleting a file, while it will break after an Apache reboot, and I don't think using bash is necessary - all shared hosts don't allow that. I tried to use flock LOCK_EX, but I failed, the actual code is $f=fopen('.lockfile','wb') or die('Unable to open lockfile'); if (!flock($f, LOCK_EX + LOCK_NB)) die('File locked'); echo 'working with file for a minute'; sleep (60); flock($f, LOCK_UN); fclose($f); Code (markup): but the script would run 2 and more copies. Please help me....
The db method has the same issue. If the program dies it will leave the lock in place and you'll need to manually remove the lock to get it running again. The code in the OP works for me as written.
Maybe I'm not getting the question, but sometimes when I need to make a file 'unavailable' at least, I just rename it, or if it's included in a bunch of other things, just duplicate it, rename the backup something else, then wipe the original one. Then replace it at the end