Jump to content

Alternatives to php unlink to stop an overlapping script run?


matt002

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.