Running PHP scripts from cron jobs

Sometimes we have  to run a simple php script using the “standard” cron job.
A typical method for operating PHP programs from a cron job is to use a command-line system such as curl or wget. For example, the cron job operates a control just like the following command:

curl http://example.com/script.php

In this command, curl retrieves the website, which then operates the PHP script.
However, there is a better way to run PHP programs on your website from cron jobs. You can run the program straight by using the PHP command-line translator. This technique is just as efficient, and usually quicker. The following command reveals how to run a script using the PHP command-line interpreter:

/usr/local/bin/php -q /home/username/public_html/script.php

In this example, the PHP command-line operates the script.php file. The -q option allows quite mood, which stops HTTP headers from being shown.
Depending on the rule in your PHP program,it will only run if it is called from the appropriate directory. The following command reveals how to call a PHP program from a particular directory:

cd /home/username/public_html/; /usr/local/bin/php -q script.php

If your script needs special settings options, you can use a customized php.ini file. The -c option allows you to call a PHP program using a customized php.ini file:

/usr/local/bin/php -c /home/username/php.ini /home/username/public_html/script.php