Run W3 Total Cache Function with Crontab-Collection of common programming errors

Ok. I’m really stumped on this one.

Basically, I need to call a function for the WordPress plugin W3 Total Cache as part of a cron job in crontab. I’d like to automatically clear the entire page cache nightly.

Here’s the code that works fine within wordpress that I need to call:

if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
} 

I’m currently using the following script:

#!/usr/bin/php


and the command line:

php -q /path-to-file/flushtest.php

I used the wp_mail function to test and make sure I’m getting something.

The script is working fine except that the page cache is never flushed. I get the email and there aren’t any errors in the log either.

Any ideas?

Thanks for your help.