Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have ubuntu setup with lamp and I was wondering what I would type to start a php page say at 2am everyday. I am still studying how crontab works so I can't test to see which one works.

So if I have something like this how would I put in the php page with parameters?

30 18 * * * http://myip/mypage.php?action=do_something

Would I enter it like that or with absolute path? Like this

30 18 * * * /var/www/mypage.php?action=do_something
share|improve this question
add comment

2 Answers

You definitely want to use method one. That is

30 18 * * * wget -O - -q -t http://myip/mypage.php?action=do_something

As this will make the file be fetched with wget (a file downloading program) through the usual web route. This means that when apache handles the request, it will cause php to interpret that script and you would have run the script.

I'm fairly certain it's also possible to run this using method 2, by calling the php-cli application and passing the path to your script as an argument, but in most cases that would not make any real difference.

share|improve this answer
add comment

The command you place in your cron depends on how the php file is actually written. If the file is a script under a webserver then wget as mentioned will work fine. Notice with the command above the -O means the output will be written to file, -q is quiet, -t is for limiting the number of retries.

However if the php script is a shell script, wget is useless. In that case the file has to be executable and your cron command would look like:

30 18 * * * /usr/bin/env php /path/to/script
share|improve this answer
add comment

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.