Byron Posted September 3, 2011 Posted September 3, 2011 Here's a way to have 7 seperate cron jobs but only use one of your allowed two cron jobs. I think I posted this a long time ago but since somebody recently posted about how many cron jobs they were allowed, I thought I would post it again. This simple script will let you run a cron job for every day of the week. Create a php file and name it something like "curl-cron.php" and paste the code below into the file: <?php $today = date("w"); $array = array( "http://url-sun.php", "http://url-mon.php", "http://url-tue.php", "http://url-wed.php", "http://url-thu.php", "http://url-fri.php", "http://url-sat.php" ); $url = $array[$today]; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_exec($ch); curl_close($ch); ?> Then go to your cron manager at your cpanel and create a cron job to run once every 24 hours. Something like this: php -q /home/byron/public_html/curl-cron.php >/dev/null 2>&1 Then edit each day of the week inside the curl script above with a cron job. I use it to empty out old files in several directories on my site.
PenTester Posted September 3, 2011 Posted September 3, 2011 What is the use of it? i have never heard about cron job!
jje Posted September 3, 2011 Posted September 3, 2011 A cron job is a scheduled task that is run every so often (specific to the webmaster). Every time a cron job is run, it executes a command onto the server. HelioHost has a limit of 2 cron runs (not jobs, runs) per day. For example, you could make a cron job that clears a MySQL Database every 12 hours. However, with byron's script you can do much more advanced scripts
Piotr GRD Posted September 3, 2011 Posted September 3, 2011 @ PenTester Windows equivalent is task scheduler. If you're using Windows most probably you have seen it in control panel. What it is doing is practically the same like cron on Unix-like systems. http://en.wikipedia.org/wiki/Cron
Byron Posted November 4, 2011 Author Posted November 4, 2011 My cron script is legal the way it's set up. We are allowed 2 cron runs a day, but we can have 50 cron jobs if we want, just as long as only 2 out of that 50 get run in a 24 hour period. So with my script, I'm just using one of my allowed two cron runs and using it to run 7 tasks, each one on a different day of the week. I clean out several folders on my site and a few other things via cron. You could actully go to the cron manager and set it up that way, but it would be more of a pain to figure out the days and different times. I've even written one that will run a cron task for each day of the month, but I don't have enough tasks to use it.
vol7ron Posted November 4, 2011 Posted November 4, 2011 My cron script is legal the way it's set up. We are allowed 2 cron runs a day, but we can have 50 cron jobs if we want, just as long as only 2 out of that 50 get run in a 24 hour period. So with my script, I'm just using one of my allowed two cron runs and using it to run 7 tasks, each one on a different day of the week. I clean out several folders on my site and a few other things via cron. You could actully go to the cron manager and set it up that way, but it would be more of a pain to figure out the days and different times. I've even written one that will run a cron task for each day of the month, but I don't have enough tasks to use it. Byron, please don't take offense to what I said. Yes your script is set up legally, but I think users here will abuse this.Essentially, you're suggesting to set up your own scheduler because of the limit that is imposed. Imagine if I did this:run a script that runs every minute of every daythe script parses what time it is and runs certain programs based on what time it isSure I'd be running one script, which follows heliohosts rules, but it calls multiple other scripts on a schedule, circumventing the rules that cron is trying to restrict. In programming terms, this is called a "wrapper." I think the sole reason of imposing the restrictions is to reduce the impact the scripts are imposing on the server, so if we created our own scheduler, we would be getting around this limitation and hurting the server. As for your post, I was saying that instead of having different scripts for each day of the week, you could just run one script at the same time every day, which runs different functions based on what day/time it is.
Byron Posted November 4, 2011 Author Posted November 4, 2011 Imagine if I did this:run a script that runs every minute of every daythe script parses what time it is and runs certain programs based on what time it isIf you did that and you were using cron to run your script every minute of the day, I would suspend your account. If you did it by some outside cron service then we don't have any problems with that.I was saying that instead of having different scripts for each day of the week, you could just run one script at the same time every day, which runs different functions based on what day/time it is.It's all the same whether I have multible functions inside one script or I divide it up into seven scripts. Only one script is getting run once every 24 hours. Like I said ealier, I could actually go to the cron manager and do exactly what I'm doing now by setting up several cron tasks, each task with a different script. Anyway, we (the administrators) keep an eye on cron jobs and nobody goes un-noticed.
vol7ron Posted November 4, 2011 Posted November 4, 2011 Anyway, we (the administrators) keep an eye on cron jobs and nobody goes un-noticed. now that's the stuff, Hostess.
Xoviat Posted November 24, 2011 Posted November 24, 2011 If you did that and you were using cron to run your script every minute of the day, I would suspend your account. If you did it by some outside cron service then we don't have any problems with that. Does anyone have a recommended outside cron service? I wish to implement a cron-job which kicks users who have been inactive for over 1 hour. I would probably run it every hour.(A tiny task compared with other things possible with a cronjob, but as with all things, rules exist because some one at some point has done something incredibly stupid). I've never considered to possibility of an external service before- any recommendations?
Xoviat Posted November 24, 2011 Posted November 24, 2011 Just did the math on their premium system. 1 cron job / hour for one year = $90. Thinking about it some more, I have a better idea for the time being.. There's actually nothing stopping me from writing a page which makes ajax requests according to an array of timers and reads/updates a mysql_table on timer expiry. Of course that means the jobs are dependent upon my connection. Nothing i'm doing here is life or death, just basic maintenance, so it shouldn't matter.
Byron Posted November 24, 2011 Author Posted November 24, 2011 You don't need the premium plan. You can have a cron job run every hour for free. I actually have 3 cron jobs with them that run every hour for free.
Xoviat Posted November 24, 2011 Posted November 24, 2011 I've misread their system it seems. I thought resource points were taken up per execution, not as a fixed value for the task. I'll give it a go. That means theoretically that you could have 12 hourly concurrent runs without a log, for free and still have enough pts left for a logged daily run.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now