Getting past Cron Manager constraints

I started to look at the Cron Manager that GoDaddy.com offers for it’s Linux shared hosting accounts. It’s a web-based interface (hosting control center v2.10.0) rather than dealing with crontab directly. I quickly discovered some problems that I needed to work around. First, I can only have a maximum of 10 jobs. The next issue is that they constrain the minute that the job runs. It has to be a multiple of five. My original need was to have a job run every minute, and use sleep commands to run some php code every 15 seconds.

I found that they offer an advanced form which enabled me to run the job twice in an hour, so if I choose to run a job at 5 minutes past the hour, it will also run at 35 minutes past. With this, I figured I could make six jobs to execute a PHP page at 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, and 55 minutes past the hour. Ok, this was a start – but not good enough. I need the site to execute events every 15 seconds at most.

I had a problem with the limitations of crontab being executed by a minute at most. Looking at Chris Stephens suggestion about the sleep command, I noticed that I could run multiple commands with one job simply by separating them by semicolons. I could pull this off by having my jobs to continuously poll the php page every 15 seconds for five minutes. It was a long shot, but I figured I would see if it would work. The manager accepted my long list of commands. I then made some changes to my code and was able to confirm that my database was being updated every 15 seconds. For those of you who are interested, here is my command. It is 20 calls to a PHP page delimited with 19 sleep commands.

/web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi- bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi- bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi- bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi- bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 15; /web/cgi- bin/php5 “$HOME/html/event.php”

There are a few problems with this setup though. A PHP call may not take 0 seconds, so the current job could eventually overlap into the next job. The next is that if the job fails for some reason, the next call to a PHP page will not occur for (at most) five minutes. That could be a long wait for some time senstive events.

I could have used 10 jobs in total and attempted to execute every 3 minutes, but the cron manager limits me to choose my commands to execute every 5 minutes (not 3). However, there would be a way to use all 10 jobs by staggering. In all, I need 120 calls to the PHP page every 30 minutes (30 minutes divided by 15 = 120). Ten jobs would only need to call the page 12 times for the duration of the job. The delay between each PHP call would be two and a half minutes (30 minutes divided by 12 = 150 seconds = 2:30). So with staggaring, I could simply insert a sleep event first to delay the job from starting by 15, 30, 45, 60, 75, etc. seconds. If a job has a problem, or tends to be running a bit long, the next job picks up the next workload within 15 seconds. There are problems with this approach as well. First, you have 10 jobs constantly running at the same time for 30 minutes. I don’t know what kind of effect that would have on resources. The next problem is that during a server reboot, you would need to wait at most 30 minutes before the jobs start running again (If server comes back online at 12:01 or 12:31, jobs will not run until 12:30, 1:00).

sleep [delay 15,30,45,etc.]; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”; sleep 150; /web/cgi-bin/php5 “$HOME/html/event.php”

posted by Dedric Mauriac on Applewood using a blogHUD : [blogHUD permalink]

Comments are closed.

%d bloggers like this: