• Resolved michaelwp85

    (@michaelwp85)


    W3TC version 2.2.3 throws warnings.

    Warning: Undefined array key "timeout" in ....plugins/w3-total-cache/Cache_Redis.php on line 99
    Warning: Undefined array key "retry_interval" in ...plugins/w3-total-cache/Cache_Redis.php on line 100
    Warning: Undefined array key "read_timeout" in ...plugins/w3-total-cache/Cache_Redis.php on line 101

    How to reproduce:
    Use redis to cache the W3TC config.
    Set W3TC_CONFIG_CACHE_ENGINE to redis.

    Root cause:
    Cache_Redis.php 99-101:

    $this->_timeout                = $config['timeout'];
    $this->_retry_interval          = $config['retry_interval'];
    $this->_read_timeout            = $config['read_timeout'];

    The config that is returned in ConfigCache 74:

    $engineConfig = array(
        'servers' => explode( ',', W3TC_CONFIG_CACHE_REDIS_SERVERS ),
        'persistent' =>
            ( defined( 'W3TC_CONFIG_CACHE_REDIS_PERSISTENT' ) ?
                W3TC_CONFIG_CACHE_REDIS_PERSISTENT : true ),
        'dbid' =>
            ( defined( 'W3TC_CONFIG_CACHE_REDIS_DBID' ) ?
                W3TC_CONFIG_CACHE_REDIS_DBID : 0 ),
        'password' =>
            ( defined( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD' ) ?
                W3TC_CONFIG_CACHE_REDIS_PASSWORD : '' ),
        'key_version_mode' => 'disabled'
    );

    The returned config is missing the keys that are expected.

    The issue was introduced in version 2.2.2.
    Downgrading to 2.2.1 removes the warnings.

    Additionally, there are multiple deprecation notices:
    Deprecated: Redis::pconnect(): Passing null to parameter #3 ($timeout) of type float is deprecated in ...plugins/w3-total-cache/Cache_Redis.php on line 506

    • This topic was modified 2 years, 4 months ago by michaelwp85.
Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    Thank you for reaching out and I m happy to assist you with this.
    I’ve tried to replicate the problem, however, Redis works as expected with the PHP Redis installed.
    Have you made any changes in the db-config.php?
    What is the PHP version you are using?
    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    Hi @vmarko,

    No changes are made to the db-config.php, this file is in my git ignore and I always let w3 be responsible for creating it.

    I’m currently running PHP 8.1, but we also have loads of production sites running 8 with the same issue. And I’ve just tested 7.4 same issues.

    To be clear it’s not just using PHP Redis, it’s storing the W3TC config in Redis using the constants. Following the stack trace and looking at the code I shared this will always throw these warnings since the array keys are never filled in ConfigCache.php on line 74.

    Kind regards,
    Michael

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    Thank you for your feedback.
    Let me get back to you once we investigate this and Have more information.
    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    Thanks, @vmarko.
    If you need more input or a git repo to be able to reproduce the issue please let me know.

    P.S.
    I don’t think the warnings are breaking anything at the moment but it’s not possible to configure certain settings and it is flooding logs and CLI output.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    Thank you for your patience.
    1. The settings fields for Redis should be checked to ensure that they can’t be saved as blank
    2. The 0 defaults should be checked to ensure that they are being interpreted as int 0
    3. Try adding the lines below in ConfigCache.php lines 86+ See below:

    case 'redis':
    			$engineConfig = array(
    				'servers' => explode( ',', W3TC_CONFIG_CACHE_REDIS_SERVERS ),
    				'persistent' =>
    					( defined( 'W3TC_CONFIG_CACHE_REDIS_PERSISTENT' ) ?
    						W3TC_CONFIG_CACHE_REDIS_PERSISTENT : true ),
    				'dbid' =>
    					( defined( 'W3TC_CONFIG_CACHE_REDIS_DBID' ) ?
    						W3TC_CONFIG_CACHE_REDIS_DBID : 0 ),
    				'password' =>
    					( defined( 'W3TC_CONFIG_CACHE_REDIS_PASSWORD' ) ?
    						W3TC_CONFIG_CACHE_REDIS_PASSWORD : '' ),
    		'key_version_mode' => 'disabled',
                    'timeout' => 0,
    		'retry_interval' => 0,
    		'read_timeout' => 0,
    			);
    			break;

    To clarify add the lines:

    'timeout' => 0,
      'retry_interval' => 0,
      'read_timeout' => 0,

    Just after the line:

    'key_version_mode' => 'disabled'

    Let me know if this helps!

    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    @vmarko thanks for your reply but this is not my code, this is the W3TC plugin code. This is a bug in the plugin not in my codebase. That’s why I’m posting here.

    https://plugins.trac.www.ads-software.com/browser/w3-total-cache/trunk/ConfigCache.php#L73

    This config ($engineConfig) is passed to the following constructor:
    https://plugins.trac.www.ads-software.com/browser/w3-total-cache/trunk/Cache_Redis.php#L91

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    Thank you for your feedback.
    I understand this, and this why I asked you to add those lines to /wp-content/plugins/w3-total-cache/ConfigCache.php
    So can you please add the following to the mentioned file

     'timeout' => 0,
      'retry_interval' => 0,
      'read_timeout' => 0,

    Just after the line 'key_version_mode' => 'disabled'
    and see if the problem persists.
    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    Hi @vmarko,

    Sorry, I thought you suggested a fix instead of requesting me to check if this would resolve the problem.
    Looking at the code I already knew this would fix it. But I double-checked and can confirm this resolves the issues. Adding the configuration values will remove the warnings.

    The better fix would be to retrieve these values from the stored config instead of hardcoding values to 0.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    Thank you for your feedback.
    Thank you for your confirmation. Let me bring this to the team for more testing and I’ll get back to you.
    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    @vmarko Thanks!

    Quick question for any future issues if they may arise, would it be better to create a ticket on GitHub or report it here? I could try to provide a PR on GitHub to resolve the issue.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @michaelwp85

    The Github repo should be used for the PR, and confirmed bugs so feel free to create a pull request which will be reviewed by the devs.

    Thanks!

    Thread Starter michaelwp85

    (@michaelwp85)

    Plugin Author Joe Cartonia

    (@joemoto)

    @michaelwp85 Thank you for your contribution. We’ll include this fix in the next patch release (2.2.4).

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Undefined array key “timeout”’ is closed to new replies.