Cron Jobs 调用带有变量的 PHP 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3872679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:21:14  来源:igfitidea点击:

Cron Jobs calling a PHP script with variables

phpcron

提问by Nick

Is it correct to use the following command in a cron job:

在 cron 作业中使用以下命令是否正确:

/usr/bin/php -q /home/**/public_html/scores.php?date=12/05/2009

/usr/bin/php -q /home/ **/public_html/scores.php?date=12/05/2009

I haven't found any supportive article / material to answer it, hence i am putting forth this question to the community.

我还没有找到任何支持性的文章/材料来回答它,因此我向社区提出了这个问题。

So the question is is there a way for me to include a variable in a cron job calling a PHP script?

所以问题是有没有办法让我在调用 PHP 脚本的 cron 作业中包含一个变量?

Thanks

谢谢

回答by Dennis

in cron jobs, here is how you should pass the argument

在 cron 工作中,这是您应该如何传递参数

/usr/bin/php -q /home/**/public_html/scores.php date=12/05/2009

*take note there is no "?"

*注意没有“?”

回答by BBonifield

Nick, take a gander at http://php.net/manual/en/features.commandline.php.

尼克,看看http://php.net/manual/en/features.commandline.php

What you want to do is pass arguments in in the form of php -f scores.php '12/05/2009'. At that point, you'll just look at the $_SERVER['argv']to get the value.

您想要做的是以php -f scores.php '12/05/2009'. 此时,您只需查看$_SERVER['argv']即可获得值。

回答by BaneStar007

I had the same problem, my quick workaround was to create a seperate file with the parameters declared inside it, and then 'include' the original Cron file.

我遇到了同样的问题,我的快速解决方法是创建一个单独的文件,其中声明了其中的参数,然后“包含”原始 Cron 文件。

i.e.:

IE:

$date = '12/05/2009';

include ('scores.php');

回答by havefun

Use this

用这个

/usr/bin/php -q /home/**/public_html/scores.php 12/05/2009

回答by reko_t

You can setup a cronjob to fetch it from your server:

您可以设置一个 cronjob 来从您的服务器获取它:

wget -q -O /dev/null "http://yourdomain.com/scores.php?date=12%2F05%2F2009"