我有一个基岩 wordpress 站点,composer 托管在 platform.sh 上,我已经在服务器上安装了 redis,但是 wordpress 不使用的对象缓存有问题,监控 wordpress 错误截图。
Redis 以及 PHP 扩展都很好地安装在服务器上。
platform ssh 'php -m'
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis <--
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
Connection to ssh.fr-3.platform.sh closed.
我使用插件WP REDIS
配置 wp redis
$_SERVER['CACHE_HOST'] = 'redis.internal';
$_SERVER['CACHE_PORT'] = 6379;
$_SERVER['CACHE_PASSWORD'] = '';
$_SERVER['WP_CACHE_KEY_SALT'] = env('WP_SITEURL'); // salt to prevent collisions of cached data between different sites
$_SERVER['CACHE_DB'] = 0;
测试OK
web@app.0:~/web/wp/wp-content$ wp redis cli
redis.internal:6379> ping
PONG
object-cache.php 文件位于 wp-content 文件夹中
web@app.0:~$ cd web/wp/wp-content/
web@app.0:~/web/wp/wp-content$ ls
cache index.php object-cache.php plugins themes
测试监视器
web@app.0:~$ wp redis cli
redis.internal:6379> flushall
OK
redis.internal:6379> monitor
OK
我刷新主页,它不起作用
我的插件安装
web@app.0:~/web/wp/wp-content$ wp plugin list
+------------------------------------------------+----------+-----------+---------+
| name | status | update | version |
+------------------------------------------------+----------+-----------+---------+
| acf-custom-fields | active | none | 5.11.4 |
| automate-woo | active | none | 5.5.7 |
| cache-control | active | none | 2.2.5 |
| cmp-coming-soon-maintenance | active | none | 4.0.19 |
| contact-form-7 | active | none | 5.5.3 |
| disable-cart-fragments | active | none | 2.0 |
| enhancer-woocommerce-subscription | active | none | 2.9 |
| jetpack | active | none | 10.5 |
| query-monitor | active | none | 3.8.2 |
| sendcloud-shipping | active | none | 2.1.1 |
| woocommerce-sendinblue-newsletter-subscription | active | none | 2.0.33 |
| woocommerce | active | available | 5.9.0 |
| woocommerce-payments | active | none | 3.5.0 |
| woocommerce-pdf-invoices-packing-slips | active | none | 2.11.4 |
| load-templates | active | none | 1.0 |
| woocommerce-subscription | active | none | 3.1.6 |
| wp-mail-smtp | active | none | 3.2.1 |
| wp-redis | active | none | 1.1.4 |
| wordpress-seo | active | none | 17.9 |
| bedrock-autoloader | must-use | none | 1.0.3 |
| disallow-indexing | must-use | none | 1.0.0 |
| register-theme-directory | must-use | none | 1.0.0 |
+------------------------------------------------+----------+-----------+---------+
编辑:当我使用 wp redis info 时,我收到错误 WP Redis object-cache.php file is missing from the wp-content/ directory,但 object-cache.php 文件在 wp-content 中。
web@app.0:~/web/wp/wp-content$ wp redis info
Error: WP Redis object-cache.php file is missing from the wp-content/ directory.
wp-redis/cli.php
* $ wp redis info
* +-------------------+-----------+
* | Field | Value |
* +-------------------+-----------+
* | status | connected |
* | used_memory | 529.25K |
* | uptime | 0 days |
* | key_count | 20 |
* | instantaneous_ops | 9/sec |
* | lifetime_hitrate | 53.42% |
* | redis_host | 127.0.0.1 |
* | redis_port | 6379 |
* | redis_auth | |
* | redis_database | 0 |
* +-------------------+-----------+
*
* $ wp redis info --field=used_memory
* 529.38K
*
* $ wp redis info --reset
* Success: Redis stats reset.
*/
public function info($_, $assoc_args)
{
global $wp_object_cache, $redis_server;
if (!defined('WP_REDIS_OBJECT_CACHE') || !WP_REDIS_OBJECT_CACHE) {
WP_CLI::error('WP Redis object-cache.php file is missing from the wp-content/ directory.');
}
if ($wp_object_cache->is_redis_connected && WP_CLI\Utils\get_flag_value($assoc_args, 'reset')) {
// Redis::resetStat() isn't functional, see https://github.com/phpredis/phpredis/issues/928
if ($wp_object_cache->redis->eval("return redis.call('CONFIG','RESETSTAT')")) {
WP_CLI::success('Redis stats reset.');
} else {
WP_CLI::error("Couldn't reset Redis stats.");
}
} else {
$data = wp_redis_get_info();
if (is_wp_error($data)) {
WP_CLI::error($data);
}
$formatter = new \WP_CLI\Formatter($assoc_args, array_keys($data));
$formatter->display_item($data);
}
}
wp-content/object-cache.php
web@app.0:~/web/wp/wp-content$ cat object-cache.php
<?php
// WP Redis
// This file needs to be symlinked or copied to wp-content/object-cache.php
// Users with setups where multiple installs share a common wp-config.php or $table_prefix
// can use this to guarantee uniqueness for the keys generated by this object cache.
if ( ! defined( 'WP_CACHE_KEY_SALT' ) ) {
define( 'WP_CACHE_KEY_SALT', '' );
}
if ( ! defined( 'WP_REDIS_OBJECT_CACHE' ) ) {
define( 'WP_REDIS_OBJECT_CACHE', true );
}
if ( ! defined( 'WP_REDIS_USE_CACHE_GROUPS' ) ) {
define( 'WP_REDIS_USE_CACHE_GROUPS', false );
}
if ( ! defined( 'WP_REDIS_DEFAULT_EXPIRE_SECONDS' ) ) {
define( 'WP_REDIS_DEFAULT_EXPIRE_SECONDS', 0 );
}
if ( ! defined( 'WP_REDIS_IGNORE_GLOBAL_GROUPS' ) ) {
define( 'WP_REDIS_IGNORE_GLOBAL_GROUPS', false );
}
WP_REDIS_OBJECT_CACHE 变量应该在 object-cache.php 文件中设置但它没有执行,为什么 wordpress 不执行该文件?
我指定它是具有只读访问权限的服务器。
已解决,object-cache.php 文件必须放在 web/app/ 的根目录下,而不是放在 web/wp/wp-content 文件夹中。