Monday, July 20, 2009

How to execute PHP files via cron in CPanel

There are two ways that I know of (I'm sure there's more) to execute php files within cron commands.

php -q /home/USER/public_html/cron/path-to-file.php

This first method will utilize relative paths. Meaning if within this file you utilize a require_once(../file.php); it will load the file accordingly. Whereas if you use the second route

/usr/bin/php -q /home/USER/public_html/cron/path-to-file.php

you must utilize absolute paths within your file. Including a file using a relative path (like ../) will throw an error, you must define the full path of the file. Save yourself a headache when you go to transfer hosts, utilize the first method.

No comments:

Post a Comment