rbrown Posted June 19, 2011 Share Posted June 19, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/ Share on other sites More sharing options...
QuickOldCar Posted June 19, 2011 Share Posted June 19, 2011 I'm pretty sure I have your system down. Only thing I could think of is comparing all the fax numbers to one another, unset any that match, and do not do the move yet on any matching ones....let the cron get it the next cycle. Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/#findComment-1231967 Share on other sites More sharing options...
rbrown Posted June 20, 2011 Author Share Posted June 20, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/#findComment-1231973 Share on other sites More sharing options...
QuickOldCar Posted June 20, 2011 Share Posted June 20, 2011 I realized it was a longer process, but also a needed process. Even if you did locking of the files, I would think you still need to find which files to lock. Which would be any matching fax numbers files. Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/#findComment-1231979 Share on other sites More sharing options...
QuickOldCar Posted June 20, 2011 Share Posted June 20, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/#findComment-1231984 Share on other sites More sharing options...
rbrown Posted June 20, 2011 Author Share Posted June 20, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/239829-suggestions-for-slowing-down-a-script/#findComment-1232018 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.