cron command to execute a php script periodically

 ̄綄美尐妖づ 提交于 2020-01-03 05:10:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!