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.

  • 写回答

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]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区