且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

脚本运行正常,当从命令行运行但不通过cron

更新时间:2023-02-22 10:53:35

请记住,cron在不同的工作目录中运行脚本,而不是你可能使用的目录。在命令行上尝试类似以下命令:

  cd / 
./path/to/your/script。 php

如果失败,请正确修改脚本中的所有路径,直到它运行。然后它将在cron中运行。


i have a php script which runs fine when executed by SSHing into my server and running it.

however the php script doesn't seem to run even though a cron job set to run it every 10 minutes.

How do I view errors produced by cron job ?

Remember that cron runs your script in a different working directory than what you're probably used to. Try something like the following on the command line:

cd /
./path/to/your/script.php

If it fails, modify all paths in your script correctly until it runs. Then it will run in cron.