问题
I am using Ubuntu. Earlier I used to run cron jobs from GUI. I have created a php script and saved it on my server. i tried to execute cron from putty,
5 * * * * path/folder/sample.php // script runs for every 5 mins
But it doesn't work.
Am I in the right direction?
Actually, where should be the command get executed dynamically?
回答1:
The most sure way is specify path to your interpreter. You should also change 5 to */5 (which mean run every five minutes nor than run at 5 minutes past each hour), try:
*/5 * * * /usr/bin/php /path/to/your/script.php
回答2:
You have to specify absolute paths to scripts and programs in crontab
, and you mustn't assume a working directory, change directory explicitly within your script. Whatever you specify as the command, cron will pass to a new bash process, so if you specify a script (opposed to binary executable) you should start the script with the shebang line:
#!/path/to/interpreter
来源:https://stackoverflow.com/questions/19664147/cron-command-to-execute-a-php-script-periodically