【问题标题】:Why Wordpress cron not running without the interaction with the website?为什么 Wordpress cron 在没有与网站交互的情况下无法运行?
【发布时间】:2017-10-07 19:40:16
【问题描述】:

我在我的 WordPress 插件中使用 Cron 作业,但如果没有用户与 WordPress 网站的交互,cron 就无法运行。有没有什么解决方案可以让我在 5 分钟后完美地运行我的 cron 而不会失败。

【问题讨论】:

  • 您使用的是wp_cron() 还是只是普通的旧cron?如果您使用的是wp_cron(),那么除非您与网站互动,否则它不会运行。
  • @dingo_d 你能建议我任何解决方案或示例
  • 尝试在这里搜索 SO。没有什么能从我的头顶自动提款机上浮现出来。

标签: wordpress cron


【解决方案1】:

如果您在计划操作中使用脚本

wp_schedule_single_event(time(),'your_function_name',array('arguments'));

如果您访问该页面,则该函数将运行。

如果您想在某个时间间隔运行您的 cron 作业,请尝试从 cpanel 设置您的作业并在命令提示符中写入此功能访问的完整路径。

class Example_cron {
    public function __construct() {
        $this->your_function_name();
    }
    function your_function_name() {
        // write your script here 
    }
}
$objct = new Example_cron();

设置此文件的 cron 路径。它将自动运行。

设置 cron 的命令:

php/usr/bin <file path>// example opt/lammp/htdocs/wp-content/plugins/<your plugin name>/<your fine name>

谢谢

【讨论】:

    猜你喜欢
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 2014-09-17
    • 1970-01-01
    • 2017-12-07
    • 2012-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多