matt002 Posted October 11, 2009 Share Posted October 11, 2009 Hi everyone, I have a script that runs every 3 seconds kickstarted by CRON every minute. I want to however stop the script overlapping itself as it sometimes does, so in short, I would like to only allow it to run once per time. So I formulated a method without using MYSQL, a simple .txt file check as follows. The only issue is sometimes and randomly it forgets to remove the file so I end up with a script not running at all. At times my script willl run for a few hours then eventually stop as the txt file hasnt deleted after one of the script run. Other times, it simply runs once and then doesnt do so again as the file or command unlink hasnt worked. The only way to then start everything again is remove the file manually using FTP. So, my question is, any ideas for simple alternatives or if not, what could be the reason for the random non deletion of the file on the server? <?php $fileN = "check.txt"; $filename = "home/public_html/serverchecks/$fileN"; if (file_exists($filename)) { exit(); }else{ $ourFileHandle = fopen($fileN, 'w') or die("can't open file"); fclose($ourFileHandle); } // Script code HERE unlink($fileN); ?> Any ideas? Thanks in advance. Matt Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.