Title: Prime Cache After Flushing Using php
Last modified: December 20, 2024

---

# Prime Cache After Flushing Using php

 *  Resolved [steven.m](https://wordpress.org/support/users/stevenmaas/)
 * (@stevenmaas)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/prime-cache-using-php/)
 * I created a php file with the below code…
 *     ```wp-block-code
       <?phprequire 'wp-load.php';w3tc_flush_all();
       ```
   
 * I placed this in the root folder. The code runs fine. Unfortunately the cache
   is not primed afterwards. How can I have it prime (load all pages from sitemap)
   after flushing?
    -  This topic was modified 1 year, 5 months ago by [steven.m](https://wordpress.org/support/users/stevenmaas/).

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

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/prime-cache-using-php/#post-18211200)
 * Hello [@stevenmaas](https://wordpress.org/support/users/stevenmaas/)
 * Thank you for reaching out and I am happy to help!
 * I would advise using wp-cli and calling `wp w3-total-cache pgcache_prime [--start
   =<start>] [--limit=<limit>]`
 * It’s not recommended to prime all pages at once (depending on the size of the
   website) and you should also enable cache priming in Performance>Page Cache and
   add the sitemap URl
 * I hope this helps!
 * Thanks!
 *  Thread Starter [steven.m](https://wordpress.org/support/users/stevenmaas/)
 * (@stevenmaas)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/prime-cache-using-php/#post-18215066)
 * That works great!
 * In Plesk I have the option to run a command with WP toolkit. The below will purge
   and (&&) prime the cache with 50 pages…
 * /usr/sbin/plesk ext wp-toolkit –wp-cli -instance-id 9 — w3tc flush posts –skip-
   plugins=false && /usr/sbin/plesk ext wp-toolkit –wp-cli -instance-id 9 — w3-total-
   cache pgcache_prime –limit=50 –skip-plugins=false
 * This works great for small sites (under 50 pages) once a day with html cache 
   set at 84600 (1 day). For larger sites I set up the same 2 commands separately
   1 to purge 1 to prime several times so the script doesn’t exceed the 180 second
   timeout. The 50 page limit appears to work in under the 180 seconds.
 * Is there a way to perform the rest of the W3TC events such as cleanup using wp
   commands? If there is a page where all your wp commands are please let me know!
   Also, what is the recommended order to run the commands: Purge, Prime, Cleanup?
 * For example I would like to perform all of what W3TC needs to do daily in one
   command string. Purge, Prime, Cleanup etc. This way I can set an early cron when
   my sites are slow (early morning).
 * I have cron disabled in WordPress and use Plesk Cron on the sites to run cron
   Jobs. Right now W3TC events are queued in the WordPress cron until Plesk runs
   the cron. I could bypass queuing the events altogether with a single command.
    -  This reply was modified 1 year, 5 months ago by [steven.m](https://wordpress.org/support/users/stevenmaas/).
    -  This reply was modified 1 year, 5 months ago by [steven.m](https://wordpress.org/support/users/stevenmaas/).
    -  This reply was modified 1 year, 5 months ago by [steven.m](https://wordpress.org/support/users/stevenmaas/).
    -  This reply was modified 1 year, 5 months ago by [steven.m](https://wordpress.org/support/users/stevenmaas/).
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [1 year, 5 months ago](https://wordpress.org/support/topic/prime-cache-using-php/#post-18215108)
 * Hello [@stevenmaas](https://wordpress.org/support/users/stevenmaas/)
 * Glad to know this works for you
 * Let me address other questions in the other topic you opened as there is no need
   to doplicate answers
 * Thanks!

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

The topic ‘Prime Cache After Flushing Using php’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [1 year, 5 months ago](https://wordpress.org/support/topic/prime-cache-using-php/#post-18215108)
 * Status: resolved