Support » Plugin: WP Cloudflare Super Page Cache » How to write codes in preloader cron job without cookies

  • Resolved powercliff

    (@powercliff)


    Hello,

    Thanks for developing such an amazing plugin!
    I have some questions about cron jobs:
    The plugin provides two cron job urls:
    1, your.example.com/********swcfpc-purge-all******
    2, your.example.com/********swcfpc-preloader******

    However, both urls seem to require a logged-in cookie, which means I cannot hit the two urls in cPanel-Cron jobs using WGET commands.
    And I cannot execute them in wordpress cron jobs:

    function wp_cf_cache_clean_preload_func() {
    wp_mail( 'example.com', 'Automatic email for cf test', 'Automatic scheduled email from WordPress to test CF cache clean and preload');
    wp_remote_get( 'your.example.com/********swcfpc-purge-all******' );
    sleep(20);
    wp_remote_get( 'your.example.com/********swcfpc-preloader******' );
    }

    I received the wp_mail(that means the cron function was called successfullly), but the following codes seemed not working, the cache in cloudflare remained the same.(I have checked the debug.log carefully to make sure that every action is logged)

    Can you teach me how to write cron job codes without logged-in permissions? Thank you!

    • This topic was modified 4 months, 2 weeks ago by powercliff.
    • This topic was modified 4 months, 2 weeks ago by powercliff.
    • This topic was modified 4 months, 2 weeks ago by powercliff.
    • This topic was modified 4 months, 2 weeks ago by powercliff.
    • This topic was modified 4 months, 2 weeks ago by powercliff.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Salvatore Fresta

    (@salvatorefresta)

    Hi @powercliff ,
    you don’t need to be logged in when you make a purge/preload request via manual cronjob, thanks to the secret key passed as swcfpc-sec-key parameter to the query.

    For example:

    https://example.com?swcfpc=1&swcfpc-purge-all=1&swcfpc-sec-key=tFHM5uZbKA1i31Pgrgc9

    This does not require a logged in user. Why you say this? Can you give me your link to test it?

    Thread Starter powercliff

    (@powercliff)

    Hello,
    I was ready to send you my preload request url through email, and I decided to do a last test before sending it. However, this time I find a different thing:
    1, The url I ready to send to you keeps sending ‘too many 301 redirects’ and the Chrome browser stopped it automatically. I encountered similar things before, and I decided to deactivate-reactivate the plugin to generate a thoroughly new preload url.
    2, I found the new generated preload url worked quite well. That’s strange. I was using the identical command the environment to hit the preload url in the past a few days, but got several different answers:
    · too many 301 redirects, the page stops to work.
    · get ‘preloader started’ message only in a logged-in browser
    · redirect to the homepage
    · get ‘Preloader started’ message, but the preloader does not start (I am sure by refreshing debug.log)

    ————————————————–
    I want to provide another tiny issue which maybe useful:
    The ‘unlock preloader’ is not working, at least in my test.
    1, start a preloader via dashboard, the debug.log immediately shows many preload urls
    2, refresh the page and the ‘unlock preloader’ button appears
    3, click ‘unlock preloader’, and the page pops up a message ‘preloader unlocked successfully’
    4, click ‘unlock preloader’ again, and the page pops up a message ‘preloader is already unlocked’
    5, refresh the page, the ‘unlock preloader’ button disappears.
    6, However, the preloader thread is still running. It still keeps fetching the rest urls regardless of the UNLOCK command until the end. Yes, I check all of the rest urls, they are all cached in cloudflare.
    ————————————————-

    Since the preload url works now, I will run my cron jobs and report the result to you in the next few days.
    Thank you!

    Thread Starter powercliff

    (@powercliff)

    I don’t know if the preload url provides extra response messages other than ‘preload started’. May I make some suggestions for it?
    I think adding the unlocker url and extra response messages would be very helpful for building an automatic bash script, by judging the status by response message and deciding the next procedure to plan.
    Thank you!

    • This reply was modified 4 months, 2 weeks ago by powercliff.
    • This reply was modified 4 months, 2 weeks ago by powercliff.
    • This reply was modified 4 months, 2 weeks ago by powercliff.
    Thread Starter powercliff

    (@powercliff)

    Thanks for your help, your plugin helps me a lot. I have solved my problem by writing a script outside wordpress to preload pages periodically 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.