freeloader Posted June 26, 2009 Share Posted June 26, 2009 Hi guys, I want to run several scripts between hours a and b daily between c and d number of times. I also want it to run on different times daily, so a static cron that runs daily is not an option. The solution I made up for this is the following (I'd like feedback both on the method used and possibly help on a little problem I ran into on the way): Example: run script test.php between 10AM and 2PM daily between 2 and 3 times a day. I have a table called 'DB_Cron' with following fields: ID (so I can link to other tables in my db)[int(10)], BeginTime[int(2)], EndTime[int(2)], NextCron[datetime], CronLog[text]. BeginTime and EndTime are my 10AM and 2PM, they are static. I would make 2 php files: cronreset.php and cronrun.php Cronreset.php runs daily at 0:00 and it creates between 2 and 3 different timestamps (depending on values in another table), it stores these in CronLog seperated by a comma and sorted on time, earliest first. The earliest he stores in NextCron. Cronrun.php is set on a 5 minute cron. Everytime it runs it checks if another 'NextCron' has 'expired'. If it has, it runs script test.php. At the end of the file it resets NextCron, grabs the next datetime from CronLog and populates NextCron with it. -- I hope all of that made some sense. My first question would be: is there a better solution for this? And second question is more of a direct php question: how can I sort the number of different datetime stamps I created in an array so that the earliest is the first one in CronLog? All help is appreciated, if anything is unclear, I'll do my best to clear it up. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/163764-dynamic-custom-cron-php-script/ Share on other sites More sharing options...
JonnoTheDev Posted June 26, 2009 Share Posted June 26, 2009 Why not write a program that can generate a new crontab each day? Quote Link to comment https://forums.phpfreaks.com/topic/163764-dynamic-custom-cron-php-script/#findComment-864096 Share on other sites More sharing options...
freeloader Posted June 26, 2009 Author Share Posted June 26, 2009 I thought about that as well, but since I can't possibly run a homeserver, I depend on external hosting at GoDaddy.com (I'm not sure if that's considered advertising or illegal around here, if it is, I'll delete the hosting company but it's relevant to the rest of my answer). Creating a new crontab daily would mean I'd have to write a script that logs into their hosting pannel and create the crontab there. Which is way more complicated than doing it like this. Thanks for the tip and reading my question though Quote Link to comment https://forums.phpfreaks.com/topic/163764-dynamic-custom-cron-php-script/#findComment-864100 Share on other sites More sharing options...
freeloader Posted June 26, 2009 Author Share Posted June 26, 2009 I've looked into that and it would really be very tough with all the security protocols, I also think it would be considered illegal by the host and I don't have shell access to input it directly into linux. Any more ideas are certainly welcome or an answer to the second sorting question. Quote Link to comment https://forums.phpfreaks.com/topic/163764-dynamic-custom-cron-php-script/#findComment-864123 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.