[英]Cron Won't Execute PHP
I have been trying to execute PHP script using cronjob, but I can't get it to work. 我一直在尝试使用cronjob执行PHP脚本,但是我无法使其正常工作。 I've tried every solution I could find with no luck.
我尝试了所有无法找到的解决方案。 Following is the process I am using:
以下是我正在使用的过程:
sudo crontab -e
*/1 * * * * /user/bin/php /var/cron.php >> /var/log/cron.txt 2>&1
PHP script works when manually executed: (cron.php) 手动执行时,PHP脚本有效:(cron.php)
<?php
file_put_contents("output.txt", "Works");
?>
When I run a script which is not php it works, for example, the following script runs every 1 minute and works 例如,当我运行不是php的脚本时,它可以工作,下面的脚本每1分钟运行一次,并且可以工作
*/1 * * * * touch /var/cron.txt >> /var/log/cron.txt 2>&1
If any of you can point out where I am going wrong I would really appreciate it. 如果您能指出我要去哪里,我将非常感激。
As Barmar mentioned in a comment , I was missing the absolute path for the output file in my script. 正如Barmar 在评论中提到的那样 ,我在脚本中缺少输出文件的绝对路径。 Once I added that to my script file got created where I was expecting it to.
一旦将其添加到脚本文件中,就可以在期望的位置创建它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.