dongpo2002 2013-05-16 16:44
浏览 119

在AWS服务器上触发定时事件

I have a web server running on AWS which is connected to a mysql database. The database has an event that run once a day. I need to run a php script on the same schedule which checks the DB and then sends Push Notifications. I don't believe I can do this from within the DB so it needs to be done on the web server. I just don't know how to do this type of thing on AWS.

I have never run a cron job but that seems like what I might want, but I don't know how this is accomplished on AWS and can it fire a php script?

  • 写回答

1条回答 默认 最新

  • dongliaoqiang8524 2013-11-05 06:44
    关注

    You have several issues going on here, the most important is getting your SSH access established (as you call it, "console access"). Without it, you won't be able to get your cron jobs setup.

    As for cron jobs, you will want to follow these steps:

    1) Setup a crontab file, probably in your home directory. Here's a sample file to get you started:

    #This file is: /home/<your-user-name>/mycronfile.cron
    #Use "crontab mycronfile.cron" to reinstall this file
    #Use "crontab -l" to list the contents of the current crontab
    #Use man 5 crontab for info
    #Format is: minute hour dayofmonth month dayofweek
    # * * * * * *
    # | | | | | |
    # | | | | | +-- Year              (range: 1900-3000)
    # | | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
    # | | | +------ Month of the Year (range: 1-12)
    # | | +-------- Day of the Month  (range: 1-31)
    # | +---------- Hour              (range: 0-23)
    # +------------ Minute            (range: 0-59)
    # , and - can be used as in 0,15,30,45 or 1-5
    
    # run my script every WEEKDAY at 3pm
    0 15 * * 1-5 php -f /Library/Developer/myscript.php
    # note that it's okay to leave out Year since I'm not using it
    

    2) Install this file as directed in the cron example above, from your home directory:

    crontab mycronfile.cron
    

    3) Confirm it's installed by typing:

    crontab -l
    

    A last note is that in your PHP scripts, you cannot use $_SERVER global variables because CLI mode does not honor those globals. All your paths must be absolute.

    评论

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: