Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The documentation says that I need to:

If your hosting account is on LINUX/UNIX system you can setup a CRON job to point to this URL http://yourUrlToThisScript.com/cron.php?cron=do&d=31

Although this is the only information they give on how to set up the cron. I know the script is working correctly because when I access the URL by a browser I receive the emails.

  1. I have looked at a couple of examples and tried reading the manual: Executing PHP files and have come up with: */1 * * * * /usr/bin/php -q /var/www/website/public/domain-manager/cron.php cron=do&d=31 >/dev/nul

Although this is not working and I don't receive any emails or errors?

  1. How can I protect this file cron.php so that it can't be executed from a browser? Maybe something like this answer although for a single file instead of a directory.
share|improve this question
    
Sorry the second "1." is supposed to say "2.", couldn't figure out why it is displaying it as a 1. –  John Magnolia Apr 28 '12 at 16:27
    
It is missing the question mark in the crontab line. –  Mircea Vutcovici Apr 28 '12 at 16:43

1 Answer 1

up vote 5 down vote accepted

There is a slight difference of how you call a PHP script and especially how it will process the given parameters. The documentation is about a HTTP GET request and you are doing a command line call of the PHP script.

Example of a HTTP GET request executed via command line:

wget -q -O  - "http://localhost/domain-manager/cron.php?cron=do&d=31"

Example of executing a PHP script via command line:

php -f /var/www/website/public/domain-manager/cron.php cron=do d=31

The main difference is how PHP will get the parameters. For the HTTP request PHP will use an interface to Apache or whatever web server you are using and fetch parameters in a $_GET array. For the command line call PHP must use the $argv array.

If the documentation requires a HTTP call I would use it, even if the command line call will be better for performance reasons and does not have such limitations.

Recommendation for your crontab:

*/2 * * * * wget -q -O  - "http://localhost/domain-manager/cron.php?cron=do&d=31" > /dev/null 2>&1

Recommendation for protecting this file from external request: Content of /var/www/website/public/domain-manager/.htaccess (in same directory)

<files cron.php>
order deny,allow
deny from all
allow from localhost
</files>
share|improve this answer
    
Absolutely blown away by this answer. You not only solved my issues but also helped me to understand why. thank you very much –  John Magnolia Apr 28 '12 at 17:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.