donglv6747 2013-06-10 22:30
浏览 24
已采纳

交互后运行php脚本x小时(cronjob)

In my php script, I want a function to be executed 2 hours after an user has registered, whether he is logged in or not. I know it has somehow to be done with cronjob, but I have never worked with it before and I don't know how to pack this all together.

How would I go about this? I have looked around for answers but I haven't found a solution. My first idea was to store timestamps in a database and collect them with a query. A cronjob would then have to be run every few minutes to keep things updated. Would that be the right way? I would also appreciate some useful links for getting into cronjobs easily. Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dsgw8802 2013-06-10 23:20
    关注

    Yes that is how I would do it.

    From command line:

    crontab -e
    

    Then enter the following on a new line:

    * * * * * php /path/to/your/cron/script.php
    

    This will run script.php every minute

    You cron script would be something like follows:

    $qry = "SELECT * FROM users WHERE signup_date < '$two_hours_after_now' AND cron_run = '0'"
    // stuff you want to do
    $qry = "UPDATE users SET cron_run = '1' WHERE id = '$id'";
    

    Hopefully this will point you in the right direction.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题