• Resolved andreescocard

    (@andreescocard)


    Hi,
    I made a website getting information from 2 other wordpress websites, the problem is i need to clear cache after 20m of all website. How can i regenerate the page cache? I tried using crawler, but it won’t work since doesn’t exist a sitemap. I currently delete all cache using cron after 20m, but i can’t regenerate the cache after it. I tried to make a curl to page (not working), but when i access the page after 20m, the page takes too long to load (since it is recreating the cache on my access).
    Any ideas of how i can regenerate the cache? In my case, regenerate home cache will solve my problem.

    My cron script:

    <?php
    define( 'WP_USE_THEMES', false ); 
    require( '/var/www/html/wp-load.php' );
    do_action( 'litespeed_purge_all' );
      
    
    $ch = curl_init('https://mywebsite.com');
    
    curl_exec($ch);
    curl_close($ch);
    
    echo "done";
    
    ?>
    • This topic was modified 3 years, 5 months ago by andreescocard.
Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support qtwrk

    (@qtwrk)

    Hi,

    simply curl won’t work , you need to mimic the full browser cache , e.g.

    curl 'https://blog.litespeedtech.com/' \
      -H 'authority: blog.litespeedtech.com' \
      -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
      -H 'accept-language: en-ES,en;q=0.9' \
      -H 'cache-control: no-cache' \
      -H 'pragma: no-cache' \
      -H 'sec-ch-ua: "Chromium";v="104", " Not A;Brand";v="99", "Google Chrome";v="104"' \
      -H 'sec-ch-ua-mobile: ?0' \
      -H 'sec-ch-ua-platform: "macOS"' \
      -H 'sec-fetch-dest: document' \
      -H 'sec-fetch-mode: navigate' \
      -H 'sec-fetch-site: none' \
      -H 'sec-fetch-user: ?1' \
      -H 'upgrade-insecure-requests: 1' \
      -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36' \
      --compressed

    specially the accept and user-agent header

    you can also check this script https://docs.litespeedtech.com/lscache/litemage/crawler/

    it runs on bash , but I believe you can adapt it to PHP

    @andreescocard

    I disagree to @qtwrk. Everything you need can be done with PHP and curl. You can find the code in the cache plugin. Almost copy and paste…..

    Thread Starter andreescocard

    (@andreescocard)

    Thanks @qtwrk i created an .sh file and added it to cron, seems to be working.

    I tried to adapt it to php, no success.

    @serpentdriver do you know in what php file it is? I looked fast into it but i haven’t found, thanks for replying too.

    @andreescocard

    There is not only 1 file you have to search for, but the solution is not a copy and paste job, so you must learn how (lib)cURL works then you can copy the code from cache plugin.

    Thread Starter andreescocard

    (@andreescocard)

    I know how cURL works, but the cache needs specific parameters on cURL to work. Actually i have already solved the problem, i am just curious how to make it work adapting to PHP, since i tried some parameters on cURL that don’t work to regenerate the cache.
    Thanks anyway

    Plugin Support qtwrk

    (@qtwrk)

    if it works on command line curl , then there is no way reason it doesn’t work on php curl , just make sure all the parameters and headers are matched on both CLI and PHP

    @andreescocard

    There is no PHP only way to warmup the cache. You need PHP and PHP curl. You don’t need any curl parameter for basic function, but depending on cache plugin settings you have to mimic different devices that can be done with User-Agent and cookies. Nevertheless and like I already said you find this in the code of the plugin. Please don’t expect a complete code documentation. Everything you need already exists and has only to be copied.

    Thread Starter andreescocard

    (@andreescocard)

    Hi
    I tought the cache was working but it wasn’t.
    When i run the curl on server, it shows on footer:
    “Page generated by LiteSpeed Cache 5.2.1 on 2022-10-18 10:38:05 ”
    But when i purge cache and access the page again, website become very slow and generate another cache (don’t understand why):
    “<!– Page generated by LiteSpeed Cache 5.2.1 on 2022-10-18 10:41:11 –>”
    Why this happens?
    Thanks

    Plugin Support qtwrk

    (@qtwrk)

    hmmmm? That’s exactly what purge does, to clean cache

    Thread Starter andreescocard

    (@andreescocard)

    yes but when i run curl again, it got stuck on the same date and time (2022-10-18 10:38:05)
    seems like the curl is generating cache but a different one

    seems like the curl is generating cache but a different one

    Optimizing is optimizing and caching is caching. 2 completely different actions. The date you see in code is the date when the page was optimzied. Caching date you can only see in log file.

    Thread Starter andreescocard

    (@andreescocard)

    But curl shouldn’t regenerate the page cache?
    The problem is that even when curl runs before, if i open the url on browser it got slow loading (generating page cache again)

    But curl shouldn’t regenerate the page cache?

    It seems you have a big missunderstanding… The crawler(curl) is for warming up the cache and nothing else. If you don’t want your cache to be warmed up, don’t run the crawler.

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Clear cache and regenerate’ is closed to new replies.