如何使用cron作业运行php文件 [英] how to run php file using cron jobs

查看:100
本文介绍了如何使用cron作业运行php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个电子邮件日程表每天运行在php页面使用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.

现在当我使用cron作业运行php脚本时,它也可以正常工作,但当我把一些查询cron作业不会理解该链接。

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.

例如: http://www.wetube.org/cron.php?id= 01001 所以现在如果我试图运行这个日常使用cron工作,它不工作。

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运行命令,因为它们将通过shell,所以运行PHP将使用本地路径。

Cron runs commands as they would be ran via the shell, so running PHP would use local paths.

您需要使用命令:

php /home/USER/public_html/cron.php

或者如果需要包含查询字符串,请使用cURL如果已安装):

Or if including the query string is necessary, use cURL instead (if it's installed):

curl http://www.wetube.org/cron.php?id=01001

您可能希望不要将cron脚本暴露给互联网 - 将它们移动到您的网络目录之外,因为如果有人发现它们可以不断地将其重新加载到垃圾邮件您的cron脚本(即发送大量电子邮件)

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)

这篇关于如何使用cron作业运行php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆