dougou2937
2014-03-28 01:25
浏览 81
已采纳

设置Cron作业执行PHP

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.

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

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

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

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?

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?

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

图片转代码服务由CSDN问答提供 功能建议

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

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

我之前从未使用过Cron作业,因此我对它们的执行感到有点困惑。

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

我试图设置一个。 首先,在通过 crontab -e 打开crontab后,我想每分钟执行我的php页面:

1 0 0 0 1 /updateplayer.php

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

其次,为了让php页面的“重要”部分运行,我需要我的 $ _GET ['playerid'] 设置为某个玩家ID。 我希望我可以通过部分 arg1 arg2 部分完成此任务(遵循我提议的cron作业的phpexecute.php部分)。 然而,这并不像预期的那样有效。 任何人都可以帮助我完成这项工作吗?

*请注意,我确实理解该作业仅适用于作业中指定的一个playerid。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshi3818 2014-03-28 01:41
    已采纳

    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.

    The cron job would look like this:

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

    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]

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题