【问题标题】:Is this possible to set cron job without cpanel?这可以在没有 cpanel 的情况下设置 cron 作业吗?
【发布时间】:2017-03-02 18:03:58
【问题描述】:

我有一个 add_post 表单来添加新帖子,其中包括帖子标题、内容、描述和 post_date_n_time。

如果 post_date 是当前日期或过去日期,则 post 存储在数据库中作为发布,如果 post_date_n_time 是未来日期,则 post 存储在数据库中作为草稿。如果发布日期是未来日期,那么我将 post_id 和 post_date 存储在 post_schedule 表中,如下所示-

post_schedule 表

post_id |  post_date  
   1    |  2017-03-04 19:01:00
   2    |  2017-03-04 19:30:00
   3    |  2017-12-15 16:01:00  

我想根据存储在数据库表 post_schedule 中的 post_date 和时间设置 cronjob,以便我能够更新 post_status 草稿以发布。我可以使用 setInterval 方法来实现我想要的,将 post_date 传递给 setInterval 方法,以便它按照指定的日期触发。

【问题讨论】:

  • cron 与 javascript 有什么关系?
  • 我想你不知道服务器/客户端是什么意思
  • @madalin 我在询问 cronjob 的替代方案。使用 setInterval 方法可以访问 php 页面,我可以在其中执行我想要的操作

标签: javascript jquery cron setinterval


【解决方案1】:

您不需要 Cron 作业。

function getIsDraft($item) {
    // if timestamp of item post_date is lower than return TRUE - is draft
    // else return FALSE - is published
    return strtotime($item->post_date) > time();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-18
    • 2012-05-09
    • 2018-04-09
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多