没有不值得去解决的问题,也没有不值得去学习的技术!

Why Do W3TC Scheduled Tasks Disappear After Creation? Troubleshooting WP-Cron and Redis Stale alloptions Cache

Figure 2: The new PHP process cannot read the Probe via get_option("cron"), but it clearly exists in the database

作者:

在

In the previous post, I continued troubleshooting an issue where W3 Total Cache page cache entries rarely lasted more than 2 days.

Eventually, I first identified a chain of failures that had been ongoing for some time:

Plaintext
Yoast post-sitemap.xml
        ↓
PHP-FPM 256M memory exhausted
        ↓
HTTP 500
        ↓
Joint Sitemap preheating failing for an extended period
        ↓
W3TC unable to consistently obtain the latest preheated URLs

After increasing the PHP-FPM memory_limit from the effective 256M to 512M, both the Chinese and English post-sitemap.xml returned HTTP 200, and the joint Sitemap resumed automatic updates.

At this point, I originally thought the W3TC page cache preheating issue was essentially resolved.

But upon further inspection, I discovered an even stranger problem:

Although the Prime and Cleanup cron tasks in W3 Total Cache were configured, they were not executing properly. After manually recreating them, the tasks would even disappear again.

Continuing the investigation, I ultimately reproduced a set of highly critical results:

Plaintext
cron option in the database: YES
WordPress get_option("cron"): NO

That means:

The Cron data saved in MySQL was already the new version, but what a normal PHP environment read from the Object Cache was still an old copy.

Finally, by precisely deleting options/alloptions in the Redis Object Cache, the Cron data became consistent again.

This post documents the entire troubleshooting process.


1. Sitemap Restored, but W3TC Prime Still Not Working Properly

W3 Total Cache currently has Page Cache Preload enabled.

The configuration is roughly as follows:

Plaintext
Page Cache: Disk Enhanced

Prime:
Execute every 300 seconds
Preheat 7 URLs each time

Cleanup:
Execute every 3600 seconds

The two corresponding WP-Cron Events are:

Plaintext
w3_pgcache_prime
w3_pgcache_cleanup

After the joint Sitemap was restored, I started verifying whether these two tasks were actually running properly.

I found that their status was clearly incorrect.

After recreating them, WP-CLI showed:

Plaintext
w3_pgcache_prime
2026-09-01 04:09:28
now
5 minutes

w3_pgcache_cleanup
2026-09-01 04:09:28
now
1 hour
Figure 1: The recreated W3TC Prime and Cleanup have reached their execution time
Figure 1: The recreated W3TC Prime and Cleanup have reached their execution time

The time shown here is GMT.

In Beijing time, that corresponds to:

Plaintext
12:09:28

The Prime interval is 5 minutes, and the Cleanup interval is 1 hour.

Under normal circumstances, as long as WP-Cron actually executes once, the next execution time for both tasks should advance accordingly.

But that was not the case.


2. Linux Cron Has Been Executing wp-cron.php All Along

My WordPress has disabled automatic WP-Cron triggering via frontend access:

PHP
DISABLE_WP_CRON = true

The server uses Linux Cron to directly execute the following every 5 minutes:

Plaintext
*/5 * * * * cd /data/wwwroot/www.shuijingwanwq.com && /usr/local/php/bin/php wp-cron.php >/dev/null 2>&1

So the theoretical chain is:

Plaintext
Linux crond
      ↓
php wp-cron.php
      ↓
WordPress WP-Cron
      ↓
w3_pgcache_prime
w3_pgcache_cleanup

After checking /var/log/cron, I could also confirm that wp-cron.php was indeed executing every 5 minutes.

So the problem was not:

Linux Cron not starting.

Even executing it manually:

Bash
/usr/local/php/bin/php wp-cron.php

also returned normally:

Plaintext
exit_code=0

But at that time, the times for the two W3TC Events still did not advance as expected.

So the problem had to be traced further inside WordPress Cron.


3. First Ruling Out the Most Common WP-Cron Issues One by One

Next, I checked a few of the most direct possibilities.

First, I confirmed:

PHP
wp_get_ready_cron_jobs()

I could see:

Plaintext
w3_pgcache_prime
w3_pgcache_cleanup

This means WordPress clearly determined that they had reached their execution time.

Checking further:

PHP
has_action("w3_pgcache_prime")
has_action("w3_pgcache_cleanup")

Both had also registered their callbacks.

At the same time:

PHP
get_transient("doing_cron")

No long-lingering Cron lock was found.

Therefore, I gradually ruled out:

Plaintext
Task does not exist at all             ×
Task has not reached its time yet      ×
W3TC callback not registered           ×
Long-term doing_cron lock stuck        ×
Linux crond not running                ×

At this point, the problem was already somewhat unusual.


4. Even Stranger, the Two W3TC Events Later Disappeared Directly from the Database

Upon further inspection, a phenomenon even stranger than “not executing” occurred.

Reading directly from the WordPress database:

Plaintext
wp_options
option_name = cron

I found:

Plaintext
w3_pgcache_prime:NOT IN DATABASE
w3_pgcache_cleanup:NOT IN DATABASE

That is to say:

The two W3TC Cron Events that had just been successfully created later actually disappeared from the real database.

If it were merely a W3TC Prime callback execution failure, it would be theoretically difficult to explain this phenomenon.

At this point, I began to suspect:

Could it be that a specific Event was not individually deleted, but rather the entire cron option had been overwritten by an old copy of data?

To verify this hypothesis, I needed an experimental task completely unrelated to W3TC.


5. Creating a Probe That WordPress Plugins Do Not Recognize at All

I first created a temporary Cron Event:

Plaintext
swq_cron_persist_probe

And scheduled its execution for about 1 hour later.

This name was generated temporarily; no existing plugin could have possibly written deletion logic for it in advance.

After creating it, I checked:

Plaintext
schedule_result=bool(true)

DB_contains_probe=YES
get_option_contains_probe=YES

This showed that the task had indeed been written to the database.

I then immediately executed:

Bash
/usr/local/php/bin/php wp-cron.php

Note:

This Probe was still about 1 hour away from expiring, so wp-cron.php at this point should not have processed it at all.

But after executing it, I checked again:

Plaintext
DB_contains_probe=NO
get_option_contains_probe=NO
next_scheduled=bool(false)

The Probe had unexpectedly disappeared.

This basically ruled out:

W3TC itself specifically clearing w3_pgcache_prime.

Because an Event with a temporarily generated name that had not yet expired also disappeared.

The real suspect became:

Plaintext
wp-cron.php starts
       ↓
Reads the old Cron array
       ↓
Executes a due Event
       ↓
Writes the cron option back
       ↓
Newly added Events are overwritten by the old array

However, this still needed further proof:

Did WordPress actually read an old copy of Cron data?


6. Key Evidence Emerges: DB=YES, but get_option=NO

So I set up a second Probe:

Plaintext
swq_cron_persist_probe_2

This time, I scheduled it for about 2 hours later.

After creating it, I queried the database directly:

Plaintext
schedule=bool(true)
DB=YES

This showed that the Event already existed in the database.

I then started a brand-new normal PHP process and read it via WordPress:

PHP
get_option("cron")

The result was:

Plaintext
get_option=NO
DB=YES
Figure 2: The new PHP process cannot read the Probe via get_option("cron"), but it clearly exists in the database
Figure 2: The new PHP process cannot read the Probe via get_option(“cron”), but it clearly exists in the database

This set of results was crucial.

Because at the same point in time:

Plaintext
MySQL:
Probe = YES

WordPress get_option("cron"):
Probe = NO

It could no longer be explained by “the task was not created successfully.”

The database clearly had the new data.

But the WordPress API was reading the old data.

Further checking in:

PHP
define("DOING_CRON", true);

yielded the same result:

Plaintext
get_option=NO
DB=YES

Therefore, the problem was also not simply:

Only the WP-Cron environment could not see the tasks.

More accurately, the option data obtained by the new normal PHP process was already inconsistent with the database.


7. Shifting Attention to W3TC Redis Object Cache

WordPress currently has W3 Total Cache Object Cache enabled:

Plaintext
Object Cache:Enabled
Engine:Redis

And WordPress’s:

Plaintext
cron

is an autoload option.

Checking the database yielded:

Plaintext
autoload=on

This means it is usually loaded along with a large number of autoloaded options into:

Plaintext
alloptions

Therefore:

PHP
get_option("cron")

It does not necessarily query MySQL directly every time.

In an environment with a persistent Object Cache enabled, it likely reads the cached:

Plaintext
group:options
key:alloptions

At this point, the previous phenomena had a very reasonable explanation:

Plaintext
cron in the database
has been updated
       ↓
alloptions in Redis
is still the old version
       ↓
new PHP process
get_option("cron")
       ↓
gets old data

But a guess was not enough, so the next step was to verify it directly.


8. Precisely Deleting alloptions Instead of Flushing All Cache

Here, I did not execute:

Plaintext
W3TC Flush All

Nor did I clear the Page Cache.

Because the entire troubleshooting effort was originally to figure out the abnormal page cache lifecycle issue; flushing all page cache at this point would instead disrupt subsequent observations.

So I only targeted:

Plaintext
options / alloptions

for minimal-scope handling.

Initially, after deleting it via WP-CLI, an interesting situation occurred:

Plaintext
alloptions=bool(true)

But the new normal PHP process still showed:

Plaintext
get_option=NO
DB=YES

This indicated that in the current environment:

There is a discrepancy between the actual observation results of Object Cache in WP-CLI versus normal PHP.

Therefore, I later switched to executing in the same normal PHP environment as wp-cron.php:

PHP
wp_cache_delete("alloptions", "options");

The result:

Plaintext
delete_alloptions=bool(true)

Immediately after, I started a new normal PHP process to read it again.

This time, it changed to:

Plaintext
get_option=YES
DB=YES
Figure 3: After deleting options/alloptions in the normal PHP environment, get_option("cron") immediately became consistent with the database again
Figure 3: After deleting options/alloptions in the normal PHP environment, get_option(“cron”) immediately became consistent with the database again

This before-and-after comparison was very direct:

Plaintext
Before deletion:

get_option=NO
DB=YES

        ↓

Delete alloptions

        ↓

After deletion:

get_option=YES
DB=YES

Therefore, at this point, it was fairly clear to confirm:

The direct failure mechanism for the disappearance of WP-Cron Events this time is related to the stale alloptions Object Cache.


9. Why Does a Stale alloptions Cause Future Events to Disappear as Well?

All WordPress Cron tasks are essentially stored in:

Plaintext
option_name = cron

This structured data.

If the database already contains:

Plaintext
Cron Version B

Which includes:

Plaintext
Old tasks
+
Newly added W3TC Prime
+
Newly added Cleanup
+
Probe

But a certain PHP process still retrieves from the Redis Object Cache:

Plaintext
Cron Version A

Which only contains:

Plaintext
Old tasks

Then, when this process executes a due task and triggers:

Plaintext
wp_reschedule_event()

or:

Plaintext
wp_unschedule_event()

it may write the old array it holds back to the database.

Consequently:

Plaintext
Database Version B
       ↓
Overwritten again by Version A
       ↓
All newly added Events disappear

This also explains the previous most abnormal phenomenon:

Why a Probe scheduled to run in 1 or 2 hours would also disappear prematurely after running wp-cron.php.

It was not “executed” by Cron.

It was more likely:

The new version of Cron data containing it was entirely overwritten by the old version.


10. Re-establishing Prime, Cleanup, and the Probe

After cleaning up the stale alloptions, I recreated:

Plaintext
w3_pgcache_prime
w3_pgcache_cleanup

And retained:

Plaintext
swq_cron_persist_probe_2

for continued verification.

Subsequent database checks showed:

Plaintext
DB w3_pgcache_prime=YES
DB w3_pgcache_cleanup=YES
DB swq_cron_persist_probe_2=YES
Figure 4: W3TC Prime, Cleanup, and the test Probe all exist again in the database
Figure 4: W3TC Prime, Cleanup, and the test Probe all exist again in the database

Because of the limited display space in the terminal, the screenshot does not fully include the preceding creation commands.

However, what really needs to be confirmed here is the final database state:

Plaintext
Prime   = YES
Cleanup = YES
Probe   = YES

This indicated that all three Events now existed simultaneously.

I also checked their execution times:

Plaintext
w3_pgcache_prime
05:39:35 GMT

w3_pgcache_cleanup
05:39:35 GMT

swq_cron_persist_probe_2
07:34:18 GMT

Prime and Cleanup had already expired, while the Probe was still nearly two hours away from executing.

This was perfect for testing wp-cron.php again.


11. Executing wp-cron.php Again—This Time It Finally Worked

After executing:

Bash
/usr/local/php/bin/php wp-cron.php

I checked again.

Prime went from:

Plaintext
05:39:35 GMT

to:

Plaintext
05:44:35 GMT

Exactly:

Plaintext
+5 minutes

Cleanup went from:

Plaintext
05:39:35 GMT

to:

Plaintext
06:39:35 GMT

Exactly:

Plaintext
+1 hour

And the Probe:

Plaintext
07:34:18 GMT

remained completely unchanged.

In the database:

Plaintext
DB w3_pgcache_prime=YES
DB w3_pgcache_cleanup=YES
DB swq_cron_persist_probe_2=YES

also all continued to exist.

Figure 5: After the fix, Prime advanced by 5 minutes normally, Cleanup advanced by 1 hour normally, and the future Probe remained unchanged
Figure 5: After the fix, Prime advanced by 5 minutes normally, Cleanup advanced by 1 hour normally, and the future Probe remained unchanged

The results this time formed a stark contrast with the failure state.

Before the fix:

Plaintext
Execute wp-cron.php
        ↓
Future Probe disappears

After the fix:

Plaintext
Execute wp-cron.php
        ↓
Prime +5 minutes
Cleanup +1 hour
Probe unchanged

At this point, the manual testing had formed a closed loop.


12. Finally, I Needed to Prove That System Cron Also Works Properly

Manual execution working was not enough.

The production environment actually relies on Linux crond:

Plaintext
*/5 * * * *

So in the end, I did not manually execute wp-cron.php again; instead, I waited for the next system Cron.

At 13:45:01, /var/log/cron clearly showed:

Plaintext
Sep 1 13:45:01 ...
/usr/local/php/bin/php wp-cron.php
Figure 6: Linux crond automatically executed wp-cron.php in the production environment at 13:45:01
Figure 6: Linux crond automatically executed wp-cron.php in the production environment at 13:45:01

Due to the limited terminal display space, this screenshot only retained the actual execution record of the system Cron.

Subsequently, I continued checking the W3TC Event status. Prime had automatically advanced from the previous:

Plaintext
05:44:35 GMT

to:

Plaintext
05:49:35 GMT

While the not-yet-due Cleanup still remained at:

Plaintext
06:39:35 GMT

This meant that the real production chain was also restored:

Plaintext
Linux crond
       ↓
php wp-cron.php
       ↓
WordPress Cron
       ↓
w3_pgcache_prime
       ↓
Next execution time +5 minutes

So ultimately, it was not:

Only working properly with manual execution.

The real Cron running every 5 minutes on the system was also able to drive W3TC Prime properly.


13. What Can Be Definitively Confirmed This Time?

Through this round of testing, several conclusions became fairly clear.

1. Linux crond Is Not Broken

The logs consistently showed:

Plaintext
Executing wp-cron.php every 5 minutes

After the fix was completed, the same Cron configuration indeed allowed Prime to advance automatically.

So there was no need to modify Linux Cron.


2. wp-cron.php Itself Is Also Not Broken

During the failure:

Plaintext
php wp-cron.php

Although it returned:

Plaintext
exit_code=0

its behavior was abnormal.

After cleaning up the stale alloptions, the exact same:

Plaintext
php wp-cron.php

immediately returned to normal.

So the problem was not with the wp-cron.php file itself.


3. W3TC Prime / Cleanup Callback Itself Is Not Broken

After restoring consistency:

Plaintext
Prime   +5 minutes
Cleanup +1 hour

Both perfectly matched the current W3TC configuration.

Therefore, there was also no need to modify the Prime callback.


4. The Direct Failure Mechanism Has Been Located at Stale alloptions

The most critical test result remains:

Plaintext
DB=YES
get_option=NO

Subsequently:

Plaintext
delete alloptions

Immediately changed it to:

Plaintext
DB=YES
get_option=YES

This is the most important set of evidence in the entire troubleshooting process.


14. But the Deepest Root Cause Is Not Fully Resolved Yet

Here, two concepts need to be distinguished:

Finding the direct failure mechanism does not mean the deepest root cause has been found.

We now know:

Plaintext
alloptions in the normal PHP environment
had stale data

But it is not yet fully explained:

Why was the autoload option in the database updated, but this Redis Object Cache was not synchronously invalidated?

My WordPress environment is also somewhat special.

It currently involves at least:

Plaintext
www.shuijingwanwq.com
en.shuijingwanwq.com
admin.shuijingwanwq.com

The backend is primarily accessed via:

Plaintext
admin.shuijingwanwq.com

while using Polylang to manage Chinese and English content.

Previously, to handle caching issues between Polylang and W3 Total Cache in a multi-domain environment, I had already added an MU Plugin.

But from this situation:

The existing compatibility handling may not have covered the complete multi-domain cache consistency issue.

However, it is not yet possible to directly assert:

Plaintext
admin domain
        ↓
causes stale alloptions

Because I still need to confirm:

  • Whether the Redis namespace used by WP-CLI and normal PHP is exactly the same;
  • Whether the Object Cache keys are truly identical across the three Hosts: admin, www, and en;
  • Whether W3TC applies special Object Cache handling for WP-CLI;
  • Which Page Cache / Object Cache scenarios the current MU Plugin actually handles.

This part is more suitable for a separate investigation in the future.


15. Page Cache and Object Cache Must Not Be Confused

This troubleshooting also made me realize one point more clearly:

Plaintext
W3TC Page Cache

and:

Plaintext
W3TC Object Cache

Although both are called “cache,” they are actually two completely different issues.

Page Cache currently uses:

Plaintext
Disk Enhanced

It primarily caches the final HTML pages.

But what affected WP-Cron this time:

Plaintext
alloptions

belongs to:

Plaintext
Object Cache / Redis

So just because a data consistency issue occurred in the Object Cache, one cannot directly assume:

W3TC’s page file cache must also be broken.

The same is true in reverse.

Next, observing whether the:

Plaintext
4-day Page Cache TTL

can finally start to gradually produce cache files lasting 2 days, 3 days, or even close to 4 days still needs to be done separately.


16. Why Didn’t I Just Flush All This Time?

Throughout the process, I tried to avoid:

Plaintext
W3TC Flush All

The reason is simple.

This server only has 2 vCPUs, and this issue was originally revisited because of a CPU alert.

If I directly cleared all page caches, a large number of pages would need to be regenerated immediately, which could instead create a new wave of cache rebuild pressure.

Moreover, this time I was able to precisely narrow the problem down to:

Plaintext
options / alloptions

So the most reasonable approach was:

Plaintext
Only handle the truly abnormal cache

rather than:

Plaintext
Clearing all caches just for convenience

Ultimately, it was indeed proven that handling just alloptions was sufficient to restore Cron data consistency.


17. Standardize WordPress Operations in the Server Terminal on WP-CLI Going Forward

To locate the problem this time, I alternated between using:

Plaintext
WP-CLI
Normal PHP CLI
wp-cron.php
Direct database queries

This was necessary for fault diagnosis.

Especially if I had not deliberately compared:

Plaintext
WP-CLI
vs
Normal PHP

I might not have discovered the discrepancy:

Plaintext
DB=YES
get_option=NO

However, mixing them like this for daily operations over the long term will increase comprehension costs.

Therefore, I plan to generally follow one principle going forward:

Plaintext
Daily WordPress management in the server terminal
→ Prioritize WP-CLI

When needing to verify the real execution environment of Web / PHP / WP-Cron
→ Only then temporarily use normal PHP

As for the current system Cron:

Bash
/usr/local/php/bin/php wp-cron.php

I do not plan to change it to:

Bash
wp cron event run --due-now

for the sake of “formal consistency” for the time being.

Because the existing production chain has already been verified in practice:

Plaintext
Linux crond
→ php wp-cron.php
→ W3TC Prime

It is currently running normally.

Until the Object Cache discrepancy between WP-CLI and normal PHP is fully investigated, there is no need to additionally change a production entry point that is already working properly.


18. Three Layers of Issues Finally Unraveled Step by Step

Looking back at this CPU alert, it ultimately unraveled into three completely different layers of problems.

The first layer was the traffic entry point:

Plaintext
Large volume of abnormal access in a short period
        ↓
EdgeOne
        ↓
Adaptive rate limiting
JavaScript Challenge
Anti-scraping traffic control

The second layer was the page preheating entry point:

Plaintext
Yoast post-sitemap.xml
        ↓
256M OOM
        ↓
HTTP 500
        ↓
Joint Sitemap unable to update for an extended period

The third layer was WordPress Cron and Object Cache:

Plaintext
cron option has been updated
        ↓
Redis alloptions still stale
        ↓
get_option("cron") reads old value
        ↓
wp-cron.php works with old Cron data
        ↓
Newly created Events are overwritten

When these three issues overlapped, it was easy to feel:

W3TC seems to be abnormal everywhere.

But after truly unraveling them layer by layer, each layer could actually be verified independently.

This was also the most valuable part of this troubleshooting.


19. Observe First Going Forward, No More Major Configuration Changes

W3TC Prime has now been restored to:

Plaintext
Every 5 minutes
Preheat 7 URLs

Cleanup:

Plaintext
Every 1 hour

The joint Sitemap has also resumed continuous updates.

The Page Cache lifecycle remains:

Plaintext
4 days

The more important thing right now is not to continue adjusting parameters, but to let the system run stably for a while.

If the cache directory gradually starts showing page caches from:

Plaintext
1 day
2 days
3 days

it will mean that the original question:

Why does a 4-day TTL rarely show page cache lasting more than 2 days?

has finally begun to be verified in practice.

As for why the alloptions inconsistency occurred this time between the multi-domain setup, Polylang, admin.shuijingwanwq.com, WP-CLI, and W3TC Redis Object Cache, that can serve as an independent issue for the next round of troubleshooting.

At least for now, the three issues unearthed from this CPU alert have finally all reached a fairly clear resolution.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系