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.

    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况