Cron 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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Cron jobs

Post by Joe »

Is it possible to create a cron job using PHP?. If so, can anyone please point my in the right direction as I am fairly new to crontab.

Joe 8)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

man cron...

SYNOPSIS
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

crontab is the program used to install, deinstall or list the tables used to drive the cron(8) daemon in Vixie Cron. Each user can
have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly.


you could generate the file with php... and then pass that to the crontab binary.....
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If you want to do something hourly,daily,weekly or monthly, some (all?) installations of Linux also have cron.hourly/, cron.daily/, cron.weekly/, and cron.monthly/ directories in the /etc/ (or wherever crontab is found) directory. Simply dumping executable files in there will have them executed at the appropriate time. I find this much easier than goofing with crontab.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

pickle, is there no permission errors when 'dumping' files into the etc/cron.time directories?. If so, what are the chances of changing the permissions on a shared server.

Joe 8)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I think all things in those cron folders is run as root, so there shouldn't be any permission errors other than possible problems with read-write-execute permissions.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

To run a cronjob on php scripts you need to compile php as cgi. Then you can easily call the script using cronjob
Post Reply