duanqiongdu9916
duanqiongdu9916
2017-05-25 13:23
浏览 27
已采纳

PHP(Laravel 5.4) - 一旦帖子达到某个年龄,就更新数据库中的条目

I just need a little advice on how I should approach this.

Basically, the application consists of a bidding platform, where users can bid on an item until the post is 12 hours old. Then the status of the "post" is set to closed and bidding is no longer allowed. So, my question is:

What is the best way to be constantly looking for posts that are 12 hours old (needs to close at the exact second) and update the database? Is it ideal to just update the post once a user attempts to load it and perform the check then?

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

我只需要一些关于如何处理这个问题的建议。

基本上,该应用程序包含一个投标平台,用户可以在该平台上对该项目进行投标,直到该帖子为12小时。 然后将“帖子”的状态设置为关闭,不再允许出价。 所以,我的问题是:

最好的方法是不断寻找12小时的帖子(需要在第二个时间关闭)并更新数据库? 一旦用户尝试加载它并执行检查,它是否理想的更新帖子?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglei2288
    donglei2288 2017-05-25 13:31
    已采纳

    That would not work.

    Consider the scenario where you have an item that needs to be expired at 23:30

    If you depend on a user to access the item, then there's also a possibility where nobody will access the item and it will stay that way.

    Laravel has a powerful Queue system where you can schedule jobs to be executed. So you can for e.g, schedule a job to run at exactly 12 hours after you create a new item.

    So this should work:

    $job = (new ExpireItem($item))
                    ->delay(Carbon::now()->addHours(12));
    

    More information in the documentation

    点赞 评论

相关推荐