Fixed Undefined array key "host" in src/XF/CacheFactory.php

Andy.N

Well-known member
Affected version
2.3 Beta 1
Upgraded from 2.2.15 to the 2.3 beta 1 on a test server from the command line and get this error.
PHP 8.2.15

An exception occurred: [ErrorException] [E_WARNING] Undefined array key "host" in src/XF/CacheFactory.php on line 192
#0 src/XF/CacheFactory.php(192): XF::handlePhpError(2, '[E_WARNING] Und...', '/home/nginx/dom...', 192)
#1 src/XF/CacheFactory.php(116): XF\CacheFactory->createMemcachedCache(Array)
#2 src/XF/CacheFactory.php(44): XF\CacheFactory->instantiate('Memcached', Array)
#3 src/XF/App.php(725): XF\CacheFactory->create('Memcached', Array, false)
#4 src/XF/Container.php(231): XF\App->XF\{closure}('', Array, Object(XF\Container))
#5 src/XF/App.php(2772): XF\Container->create('cache', '', Array)
#6 src/XF/App.php(756): XF\App->cache('registry', true, false)
#7 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#8 src/XF/Install/App.php(73): XF\Container->offsetGet('registry')
#9 src/XF/Container.php(31): XF\Install\App->XF\Install\{closure}(Object(XF\Container))
#10 src/XF/App.php(2561): XF\Container->offsetGet('addon.composer')
#11 src/XF/Install/App.php(160): XF\App->setupAddOnComposerAutoload()
#12 src/XF.php(505): XF\Install\App->setup(Array)
#13 src/XF/Cli/Runner.php(54): XF::setupApp('XF\\Install\\App')
#14 cmd.php(15): XF\Cli\Runner->run()
#15 {main}
 
Line numbers are different, but it looks like it's still an issue with 2.3 beta 3.

Code:
An exception occurred: [ErrorException] [E_NOTICE] Undefined index: host in src/XF/CacheFactory.php on line 176
#0 src/XF/CacheFactory.php(176): XF::handlePhpError(8, '[E_NOTICE] Unde...', '/home/sites/tex...', 176, Array)
#1 src/XF/CacheFactory.php(100): XF\CacheFactory->createMemcachedCache(Array)
#2 src/XF/CacheFactory.php(39): XF\CacheFactory->instantiate('Memcached', Array)
#3 src/XF/App.php(730): XF\CacheFactory->create('Memcached', Array)
#4 src/XF/Container.php(231): XF\App->XF\{closure}('', Array, Object(XF\Container))
#5 src/XF/App.php(2770): XF\Container->create('cache.symfony', '')
#6 src/XF/App.php(758): XF\App->cache('registry', true, false)
#7 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#8 src/XF/App.php(1982): XF\Container->offsetGet('registry')
#9 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#10 src/XF/App.php(1648): XF\Container->offsetGet('extension.liste...')
#11 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#12 src/XF/App.php(3118): XF\Container->offsetGet('extension')
#13 src/XF/App.php(3149): XF\App->extension()
#14 src/XF/App.php(1464): XF\App->extendClass('XF\\AddOn\\Manage...')
#15 src/XF/Container.php(31): XF\App->XF\{closure}(Object(XF\Container))
#16 src/XF/App.php(2562): XF\Container->offsetGet('addon.manager')
#17 src/XF/App.php(2081): XF\App->setupAddOnComposerAutoload()
#18 src/XF/Cli/App.php(25): XF\App->setup()
#19 src/XF.php(505): XF\Cli\App->setup(Array)
#20 src/XF/Cli/Runner.php(54): XF::setupApp('XF\\Cli\\App')
#21 cmd.php(15): XF\Cli\Runner->run()
#22 {main}
 
From the source, it just looks like 2.3 has a new format for host/port/weight. Easy enough to fix via change to config.php. For me, this:

PHP:
$config['cache'] = [
    'enabled' => true,
    'sessions' => true,
    'namespace' => 'tx',
    'provider' => 'Memcached',
    'config' => [
        'servers' => [
            [$GLOBALS['digitalPoint']['Misc']['memcacheserver'][1], 11211, 1],
            [$GLOBALS['digitalPoint']['Misc']['memcacheserver'][2], 11211, 1],
        ]
    ]
];

becomes this:
PHP:
$config['cache'] = [
    'enabled' => true,
    'sessions' => true,
    'namespace' => 'tx',
    'provider' => 'Memcached',
    'config' => [
        'servers' => [
            [
                'host' => $GLOBALS['digitalPoint']['Misc']['memcacheserver'][1],
                'port' => 11211,
                'weight' => 1
            ],
            [
                'host' => $GLOBALS['digitalPoint']['Misc']['memcacheserver'][2],
                'port' => 11211,
                'weight' => 1
            ]
        ]
    ]
];
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.3.0 Beta 6).

Change log:
Further fixes for legacy Redis cache configuration values
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom