好的。我真的被这个难住了。
基本上,我需要为 Wordpress 插件 W3 Total Cache 调用一个函数,作为 crontab 中 cron 作业的一部分。我想每晚自动清除整个页面缓存。
这是我需要调用的在 wordpress 中运行良好的代码:
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
}
我目前正在使用以下脚本:
#!/usr/bin/php
<?php
define('DOING_AJAX', true);
define('WP_USE_THEMES', false);
$_SERVER = array(
"HTTP_HOST" => "http://example.com",
"SERVER_NAME" => "http://example.com",
"REQUEST_URI" => "/",
"REQUEST_METHOD" => "GET"
);
require_once('/path-to-file/wp-load.php');
wp_mail('email@example.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');
if (function_exists('w3tc_pgcache_flush')) {
w3tc_pgcache_flush();
}
?>
和命令行:
php -q /path-to-file/flushtest.php
我使用 wp_mail 函数来测试并确保我收到了一些东西。
脚本工作正常,只是页面缓存从未被刷新。我收到了电子邮件,日志中也没有任何错误。
有什么想法吗?
感谢您的帮助。
最佳答案
现在更好的版本是使用wp-cli .最新版本 (0.9.2.8) 与此插件兼容。只需从 wordpress 目录中的任何位置运行此命令:
wp w3-total-cache flush
关于php - 使用 Crontab 运行 W3 Total Cache 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691734/