HUSKY - Products Filter Professional for WooCommerce

Turbo Mode:自动 Cron 更新为何失败(以及如何修复)

问题

用户报告 WOOF 的 涡轮模式 automatic file regeneration doesn’t work reliably:

症状:

  • 涡轮增压模式已启用“每日计划”
  • WordPress cron 作业 woof_turbo_do_recreate_file 未被创建
  • Manual file generation works perfectly
  • 自动更新生成 部分/空文件
  • File regeneration seems to never complete

影响:

  • 过时的过滤器计数显示给客户
  • 用户体验差(看到不存在的产品)
  • 需要每日手动干预

为什么会发生这种情况:两个根本原因

1. File Clearing Race Condition

When WOOF regenerates the turbo file, it follows this process:

// Step 1: Clear the file
file_put_contents($turbo_file, ''); 

// Step 2: Write new data (takes time)
foreach ($products as $product) {
    // Heavy processing for each product...
    file_put_contents($turbo_file, $data, FILE_APPEND);
}

问题:
如果您的网站有很多产品(1000+),步骤 2 可能需要 60-120 秒。如果 PHP 的 max_execution_time (通常 30-60 秒) 超过,脚本会在写入过程中终止,留下文件 空的或部分的.

2. WordPress Cron 不是真正的 Cron

WordPress cron (wp-cron.php)具有关键限制:

Not guaranteed to run – 仅在有人访问您的网站时触发
可能被阻止 - 缓存插件可能会阻止执行
没有长时间运行的任务 – killed by PHP execution limits
不稳定的时间 – 可能会延迟或根本不运行

真实场景:
您的网站流量主要来自工作时间(上午 9 点至下午 6 点)。您计划在凌晨 3 点进行涡轮再生。结果: 它从未运行过 因为没有人会在凌晨 3 点访问以触发 wp-cron.php。

可靠的解决方案:服务器端 Cron

将 WordPress cron 替换为 real server cron 独立于网站流量运行。

步骤 1:禁用 WordPress Cron

Add to wp-config.php (之前 /* That's all, stop editing! */):

/**
 * Disable WordPress cron - we'll use server cron instead
 */
define('DISABLE_WP_CRON', true);

步骤 2:添加服务器 Crontab 条目

Option A: Using PHP CLI (Recommended)

# Open crontab editor
crontab -e

# Add this line (runs daily at 3 AM)
0 3 * * * php /var/www/html/yoursite/wp-cron.php >/dev/null 2>&1

选项 B:使用 wget

# Add this line to crontab
0 3 * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

选项 C:使用 curl

# Add this line to crontab
0 3 * * * curl -s https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

Replace /var/www/html/yoursite 配合您实际的 WordPress 安装路径。

Step 3: Increase PHP Execution Limits

Add to wp-config.php:

/**
 * Increase limits for cron tasks (turbo file generation)
 */
@ini_set('max_execution_time', 300); // 5 minutes
@ini_set('memory_limit', '512M');    // 512 MB RAM

或创建 .user.ini 在您的 WordPress 根目录下:

max_execution_time = 300
memory_limit = 512M

Summary

Turbo cron 失败的根本原因:

  1. WordPress cron 不可靠(取决于流量)
  2. PHP 执行时间限制会中断长时间运行的任务

 

推荐修复:

  1. ✅ 禁用 WP_CRON
  2. ✅ 使用服务器端 cron
  3. ✅ 增加 PHP 限制
  4. ✅ 在流量较低的时段安排

结果: 可靠、自动化的 Turbo 文件再生,并为您的客户提供准确的产品计数。

Ref: https://pluginus.net/support/topic/woof_turbo_do_recreate_file-cron-job-is-missing/