Jump to content

suggestions for slowing down a script


rbrown

Recommended Posts

I have a cron script that runs every 5 mins

What it does is look a ftp directory and sees if there are any new reports.

Then it checks the report name and then figures out (based on the First and Last Name and patient id) which doctor the report belongs to and if the file needs to be faxed or emailed to the doctor. Then after it sends it whatever way, it moves the report to another directory so it doesn't try to reprocess the report.

 

The problem I have, if there are more than 2 reports uploaded that need to be faxed to the same number, the fax service can't handle it and rejects the faxes because they are trying to send multiple faxes to the same number at the same time. I have asked them twice to fix it. (their engineers are "working" on it.) So I have to manually reprocess the fax reports which defeats the purpose of having it automated.

 

So I need to be able to slow the script down on the fax section but not on the email section.

 

So I was thinking about using sleep(120) between the fax sends but if I have more than 4 faxes to go, then the cron will step on the script while it is processing.

 

I don't want to split up the script in case they fix it soon, plus I need to send the reports as fast as possible.

So I would like something I could add to the front of the script to stop the cron from trying to run the script until the reports are done.

 

So what do you suggest?

 

Link to comment
Share on other sites

that would work but, then it will take a lot longer to process them. 5 mins for each, instead of 1 1/2 mins. it takes an average of 1 min for them to send the fax. so that is why I added an extra 30 secs. They are all one page reports.

 

I remember seeing an example somewhere where you use a tmp locking file and the cron won't reprocess the script until the tmp lock file is unset, and another using session variables but I can't seem to find them again.

I have CRS setting in in my old age... lol

Link to comment
Share on other sites

I do have another idea.

 

Lets say your cron runs...you are getting the faxes, for every fax you send you also place the fax number into a text file.

Every time you are to send a new fax only perform your send fax and move file if the fax is not in the fax text file list.

 

Delete the fax list text file before next cron run.

Link to comment
Share on other sites

found it...

Also on php website for "flock"

 

$fp = fopen("lock.txt", "w");
$block = 0; 
if (flock($fp, LOCK_EX|LOCK_NB, $block)) { // do an exclusive lock 

// Insert script here....

flock($fp, LOCK_UN); 
echo "Could lock file!"; // left echo in for reference 
}else{
echo "Could not lock file!";  // left echo in for reference 
}
fclose($fp); 

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.