设置Cron作业以执行PHP [英] Set Up Cron Job To Execute PHP

查看:68
本文介绍了设置Cron作业以执行PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有文本框的php页面,该文本框接受玩家的ID号,并使用GET请求根据该ID向另一个页面发出请求,然后使用响应。

I have a php page with a text box that accepts a player's id number, makes a request to another page based off that id, using a GET request, and then uses the response.

这部分工作正常。但是,现在我想使用Cron作业来自动化该过程。

This part works perfectly. However now I would like to automate the process using a Cron job.

我以前从未使用过Cron作业,因此我对它们的执行有些困惑。

I have never used a Cron job before so I am a bit confused on their execution.

不过,请遵循此文档:[http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux -or-unix-oses /] [1

Following this documentation though: [http://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/][1

我正在尝试设置一个。首先,通过 crontab -e
打开crontab之后,如果我想每分钟执行一次php页面,我会写:

I am attempting to set one up. Firstly, after opening the crontab through crontab -e if I wanted to execute my php page every minute I'd write:

1 0 0 0 1 /updateplayer.php

我的第一个问题是,如果我希望它每分钟运行每一天,或者我没有在本文档中列出全天选项,我必须为一周的每一天写一份工作?

My first question is, do I have to write a job for each day of the week if i want it to run every day every minute or is there an all days option not listed in this documentation?

其次,为了使该php页面的重要部分运行,我需要将 $ _ GET ['playerid'] 设置为某个玩家ID。我希望我可以通过 arg1 arg2 部分的一部分(在我建议的cron作业的phpexecute.php部分之后)完成此任务。但是,这种方法的效果不如预期。谁能帮助我完成这项工作?

Secondly, in order to get the "important" part of that php page to run, I need to have my $_GET['playerid'] set to a certain player id. I'm hoping I might accomplish this through part of the arg1 arg2 portions, (following the phpexecute.php part of my proposed cron job). However this is not working as well as expected. Can anyone help me to get this job running?

**请注意,我确实了解该工作仅适用于工作中指定的一个玩家ID。

*Note that I do understand the job will only work for one playerid that is designated in the job.

推荐答案

您不需要在一周的每一天都编写一份cron作业。在您的Cron工作示例中,您可以使用星号(*)代替全部,而不是0或1。因此,第二列(小时)上的星号表示每小时运行一次。第一列(分钟)上的星号会每分钟运行一次。

You don't need to write a cron job for every day of the week. Instead of a 0 or 1 in your cron job example you can use an asterisk (*) which will mean all. So an asterisk on the second column (hour) would mean run it every hour. An asterisk on the first column (minute) would run it every minute.

cron作业如下所示:

The cron job would look like this:

* * * * * php -f /[path to dir]/updateplayer.php [playerid]

第二次部分,尽管您需要通过 $ argv变量,而不是$ _GET。在我提供的示例中,您将通过 $ argv [1]

For the second part, you can pass arguments to the PHP script although you need to fetch them through the $argv variable instead of $_GET. In the example I provided you would fetch the player id via $argv[1]

这篇关于设置Cron作业以执行PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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