Title: Clearing the cache from an external PHP script
Last modified: August 22, 2016

---

# Clearing the cache from an external PHP script

 *  [Bill Dennen](https://wordpress.org/support/users/xyzzy/)
 * (@xyzzy)
 * [12 years ago](https://wordpress.org/support/topic/clearing-the-cache-from-an-external-php-script/)
 * Hi, I’d like to clear the W3tc cache via an external php script.
 * My understanding is that this should work. In fact, it works when WP Super Cache
   is enabled, but not when W3TC is enabled.
 * Any pointers?
 *     ```
       define( 'WP_USE_THEMES', false );
       require('wp-blog-header.php');
   
       	if ( function_exists('w3tc_pgcache_flush') ) {
       		w3tc_pgcache_flush();
       	} else if ( function_exists('wp_cache_clear_cache') ) {
       		wp_cache_clear_cache();
       		}
       ```
   
 * [https://wordpress.org/plugins/w3-total-cache/](https://wordpress.org/plugins/w3-total-cache/)

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

 *  Thread Starter [Bill Dennen](https://wordpress.org/support/users/xyzzy/)
 * (@xyzzy)
 * [12 years ago](https://wordpress.org/support/topic/clearing-the-cache-from-an-external-php-script/#post-5331491)
 * Also, it does not work if I use this, instead of wp-blog-header.php:
 * `require('wp-load.php');`
 * Also, I have “Page Cache (disk advanced)” enabled ONLY. No other caches enabled.
 *  [Willie Jackson](https://wordpress.org/support/users/williejackson/)
 * (@williejackson)
 * [12 years ago](https://wordpress.org/support/topic/clearing-the-cache-from-an-external-php-script/#post-5331671)
 * Does `function_exists('w3tc_pgcache_flush')` evaluate to true?
 * If so, how do you checking that it doesn’t work?
 *  Thread Starter [Bill Dennen](https://wordpress.org/support/users/xyzzy/)
 * (@xyzzy)
 * [12 years ago](https://wordpress.org/support/topic/clearing-the-cache-from-an-external-php-script/#post-5331674)
 * Thanks WIllie. It seems as though the user account under which the external php
   script runs matters. It works when I run as root, but not as a regular user.

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

 The topic ‘Clearing the cache from an external PHP script’ 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: [Bill Dennen](https://wordpress.org/support/users/xyzzy/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/clearing-the-cache-from-an-external-php-script/#post-5331674)
 * Status: not resolved