如何使用 cron 作业运行 php 文件
我每天都使用 cron 作业在 php 页面上运行电子邮件计划.当我使用链接运行页面时,php 代码运行良好.
现在,当我使用 cron 作业运行 php 脚本时,它也可以正常工作,但是当我进行一些查询时,cron 作业将无法理解链接.
例如:http://www.wetube.org/cron.php?id=01001
所以现在如果我尝试每天使用 cron 作业运行它,它就行不通了.>
但如果我们只是删除查询它工作正常.你们知道让这个链接在 cron 工作中工作的任何代码吗?
解决方案Cron 运行命令就像它们通过 shell 运行一样,因此运行 PHP 将使用本地路径.
您需要使用如下命令:
php/home/USER/public_html/cron.php
或者如果需要包含查询字符串,请改用 cURL(如果已安装):
curl http://www.wetube.org/cron.php?id=01001
您可能想考虑不要将您的 cron 脚本暴露在互联网上 - 将它们移到您的网络目录之外,因为如果有人发现它,他们可以不断地重新加载它以向您的 cron 脚本发送垃圾邮件(即发送大量电子邮件)
I have a E-mail schedule runs everyday on php page using cron jobs. The php code workds fine when i run the page using a link.
Now when I run the php script using cron jobs, it also works fine but when I put some query the cron jobs won't understand the link.
for example: http://www.wetube.org/cron.php?id=01001
so now if I try to run this everyday using cron job it's doesn't work.
But if we just erase the query it works fine. Do you guys know any code which makes this link work in cron job?
解决方案Cron runs commands as they would be ran via the shell, so running PHP would use local paths.
You need to use a command like:
php /home/USER/public_html/cron.php
Or if including the query string is necessary, use cURL instead (if it's installed):
curl http://www.wetube.org/cron.php?id=01001
You might want to look at not exposing your cron scripts to the internet - move them to outside your web directory because if someone finds it they can constantly reload it to spam your cron scripts (i.e. sending lots of emails)
相关文章