CRON jobs according to cPanel:
This tutorial is here to provide basic information on executing php scripts for your CRON jobs.
There are two parts to your crontab: the command to run, and the interval you run it on. I won't go over how to set the intervals because cPanel has a nice interface that makes it simple for beginners or advanced users.
The way to have CRON execute your php script is to call the php interpereter and tell it to process that file. Keep in mind that it's a command and not a file (unless it's a shell/executable) you're entering. Example:
For your php script, you enter the path on the server (according to the *nix filesystem), not as a URL.
You usually don't want to expose your CRON job script in your html/web directory (/public_html, /www), since the script most likely does maintainence that could be cumbersome and might be the base of a DOS attack or an even larger security risk.
I just put mine in the /etc directory. That way no one can access/execute it via normal HTTP access. [/bin may be a better choice. I'm not sure if really matters past organization.]
Also remember that in this way PHP is not running as a CGI module, meaning you won't have access to the environment variables you're used to, like $_GET, $_POST, etc.
If you want to refine your control, keep in mind that you have access to the arguments passed to the script via $_SERVER['argv'] (which are like $_GET). You can pass commands like this: "php -q /blah/script.php -clear".
If you used print_r($_SERVER['argv']), it would return a printout for array('/blah/script.php','-clear').
NOTES:
* I don't know what the -q flag does, though... Corey had suggested it here.
Can't find it via `php --help` on my XAMPP installation.
* You might be able to run the script just using the script's name without the php command - assuming the system will recognize its type via filename extension - but I'm not sure. I can't test it at the moment because CRON is disabled for me right now (1/30/08).
Cron jobs allow you to automate certain commands or scripts on your site. You can set a command or script to run at a specific time every day, week, etc. For example, you could set a cron job to delete temporary files every week so that your disk space is not being used up by those files.
This tutorial is here to provide basic information on executing php scripts for your CRON jobs.
There are two parts to your crontab: the command to run, and the interval you run it on. I won't go over how to set the intervals because cPanel has a nice interface that makes it simple for beginners or advanced users.
The way to have CRON execute your php script is to call the php interpereter and tell it to process that file. Keep in mind that it's a command and not a file (unless it's a shell/executable) you're entering. Example:
Code:
php -q /home/username/bin/script.php
For your php script, you enter the path on the server (according to the *nix filesystem), not as a URL.
You usually don't want to expose your CRON job script in your html/web directory (/public_html, /www), since the script most likely does maintainence that could be cumbersome and might be the base of a DOS attack or an even larger security risk.
I just put mine in the /etc directory. That way no one can access/execute it via normal HTTP access. [/bin may be a better choice. I'm not sure if really matters past organization.]
Also remember that in this way PHP is not running as a CGI module, meaning you won't have access to the environment variables you're used to, like $_GET, $_POST, etc.
If you want to refine your control, keep in mind that you have access to the arguments passed to the script via $_SERVER['argv'] (which are like $_GET). You can pass commands like this: "php -q /blah/script.php -clear".
If you used print_r($_SERVER['argv']), it would return a printout for array('/blah/script.php','-clear').
NOTES:
* I don't know what the -q flag does, though... Corey had suggested it here.
Can't find it via `php --help` on my XAMPP installation.
* You might be able to run the script just using the script's name without the php command - assuming the system will recognize its type via filename extension - but I'm not sure. I can't test it at the moment because CRON is disabled for me right now (1/30/08).