Seeking alternatives for Crone Jobs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeephp
Forum Newbie
Posts: 16
Joined: Sat Apr 23, 2005 4:42 am

Seeking alternatives for Crone Jobs

Post by jeephp »

Hi
I have a site in PHP on IIS 6 and need some sort of scheduling

functionality for sending emails via php scripts, running scripts on

database etc.

I worked a bit with Crone Jobs for this however I was wondering if there

is something better then that. Site is developed in PHP / MySQL and

running on Windows 2003 with IIS 6.

Any help!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

You could use a system of timestamps, and when a page view is triggered check the time() and see if it's time to do a job. I've done this with a few sites, one for instance is a site where it takes 10-20 seconds to generate the "top 10" list, seeing as the list doesn't need to be generated every page view, I simply check if its been updated in the last 10 minutes, if not I'll serve up the old list, and at then run a shell script (written in php) to regenerate the top 10 list. This is "better" then cron in my opinion (for the situation) because during peak hours when theres a lot of traffic it gets updated every 10 minutes, but when I'm getting one hit per hour there's no need to update it every 10 minutes, it's just wasted cpu. You also need to code measures to make sure the update doesn't get done 5 times at once if 5 people load the page at the same time.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I know this probably isn't what you want to hear, but what is wrong with crons?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Is a crone job like a cron job, but with a broomstick and a pointy hat? :wink:

As you're on Windows, you could just Task Scheduler. It's not as good as Cron though.
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

I'm sure you can download thousands of automating programs off the net to do what you're asking... If they're as good as cron, is yet to be seen...
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

onion2k wrote:As you're on Windows, you could just Task Scheduler. It's not as good as Cron though.
The best of both worlds:

ICron - an implementation of Cron as a Windows service
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Jcart wrote:I know this probably isn't what you want to hear, but what is wrong with crons?


Sometimes cron just isn't available:
jeephp wrote:running on Windows 2003
I didn't use cron on my site because there's no point updating the "top 10 list" every 10 minutes if no one is going to the site for 4 hours. While I could have had the cron run a script that checks if some one has been to the site < 10 minutes ago and if not exits, I decided not to.

Also, correct me if I'm wrong (I know nothing about cron) but I beleive cron can't handle 'complex' instructions, as in cron can't run every 7 minutes for example, you have to set pre-defined times for it to run, so if your interval isn't divisible by 60 you're screwed.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Yeah you can

Code: Select all

*/7 * * * * GET http://www.example.com/test.php >/dev/null
Edit:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

hawleyjr wrote:Yeah you can
I learn summin new every day
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

jshpro2 wrote: Also, correct me if I'm wrong (I know nothing about cron) but I beleive cron can't handle 'complex' instructions, as in cron can't run every 7 minutes for example, you have to set pre-defined times for it to run, so if your interval isn't divisible by 60 you're screwed.
Honestly, I've only had *ONE* major complaint about cron, and its really more about php..

It cant say "Only run if load is under X%". If they added that, I'd want to marry Cron.

Of course, if php.ini could have a cpu usage throttle amount in php.ini the world would be a much better place.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

But instead of starting the script immediately, you could write a little wrapper in bash (or something alike) to test the load?

Code: Select all

#!/bin/bash
load=`top -n 1 | grep Cpu |  awk '{print $8}'`
if &#1111; $load < '50.0%' ] then;
  /usr/bin/php /home/user/test.php
fi
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

timvw wrote:But instead of starting the script immediately, you could write a little wrapper in bash (or something alike) to test the load?
Thats pretty much what I did, but thats just working outside the limitations.. would be nice to have it built in.
Post Reply