Page 1 of 1

[Help] How to create a cron job?

Posted: Wed Nov 15, 2006 9:27 am
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.

Posted: Wed Nov 15, 2006 10:04 am
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

Posted: Wed Nov 15, 2006 10:48 pm
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?

Posted: Wed Nov 15, 2006 10:49 pm
by John Cartwright
place your cron.php outside of the webroot, therefore nobody (except the server) will be able to access it

Posted: Wed Nov 15, 2006 10:55 pm
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?

Posted: Thu Nov 16, 2006 1:22 am
by timvw
Type "man cron" in your shell.. Happy reading. (Probably a websearch for a tutorial can be useful too).