[Help] How to create a cron job?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
phpwalker
Forum Commoner
Posts: 81
Joined: Sun Apr 23, 2006 12:18 pm

[Help] How to create a cron job?

Post by phpwalker »

I wanna update a sql statement every hours for the members storing in database, how do I accomplish that using cron jobs? I'm using Cpanel.

It has standard and Advanced (*nix style) to choose from. Which one is suitable for my task?

When I click on the standard one, it shows one field for "command to run" and few dropdown lists(hours, minutes, days, weekdays, months )

What should I type in the "Command To Run" field?

Assuming the sql statment

Code: Select all

Select *
Where Point < =100;

Thanks in advance for the help.
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 »

Put that code in a PHP file. Make it executable.

The command to run would then be:

Code: Select all

php -f /path/to/your/php/file
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
phpwalker
Forum Commoner
Posts: 81
Joined: Sun Apr 23, 2006 12:18 pm

Post by phpwalker »

Thanks for the reply, pickle.

So, I create a ../filepath/cron.php file with sql statements inside and the needed connection strings to database, am I right?

However, what if anyone who knows or guess the link, they can access to it easily? Then they might refresh the /cron.php file every minute or till the point is to the maximum - 100 pts.

Is there any way to prevent this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

place your cron.php outside of the webroot, therefore nobody (except the server) will be able to access it
phpwalker
Forum Commoner
Posts: 81
Joined: Sun Apr 23, 2006 12:18 pm

Post by phpwalker »

Woh, your so fast. Thanks man, I got it.

Is the following the only one method to run a cron job command?

Code: Select all

php -f ../filename
Is there anything else that I can learn from? How to stop it? Got a full list of command or explanation I can read?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Type "man cron" in your shell.. Happy reading. (Probably a websearch for a tutorial can be useful too).
Post Reply