php - 使用 Crontab 运行 W3 Total Cache 功能

标签 php wordpress plugins command-line crontab

好的。我真的被这个难住了。

基本上,我需要为 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/

相关文章:

plugins - MethodCall 列表在 Flutter 插件单元测试中的用途

php - html 表并用带有空行的 php 填充

php - 如何改进我的 php 添加脚本?

php - get_page_children() 不返回所有子页面

php - 从 Excel 文件获取信息然后导入到 CSS

hibernate - hibernate4-maven-plugin 生成 PostgreSQL 模式的正确配置是什么?

java - 有关 RSS 源的查询 - 我的服务器中的数据加载

php - 如何存储 MYSQL 过程的结果,以便我可以在另一个使用 PHP 的过程中使用它

php - 如何处理 WordPress 插件设置页面中的表单?

html - IE 在渲染过程中注入(inject) VBScript 标签,导致 HTML 格式错误