【问题标题】:Laminas Cache config issue after updated to PHP 8.1 from zend3从 zend3 更新到 PHP 8.1 后的 Laminas 缓存配置问题
【发布时间】:2022-07-09 01:15:52
【问题描述】:

我从事的项目最近从 Zend3 和 PHP 7.4 更新到 Laminas 和 PHP 8.1。

在 config/autoload/global.php 中

  'caches' => require __DIR__ . '/caches.php',

这是caches.php

$cacheDefault = [
    'adapter' => [
       'name'    => 'Memcached',
       'options' => [
        'servers' => Module::isRunningOnVM()
            ? ['127.0.0.1:11211']
            : Module::getMemcachedServersFromEnvironment(),
       ],
    ],
];

return [

   'cache_instrument_manager_search' => array_merge_recursive(
       $cacheDefault,
       [
        'adapter' => [
            'options' => [
                'namespace' => 'instrument_manager_search',
                'ttl'       => 20,
            ],
        ],
       ]
    ),

  'cache_weekly' => array_merge_recursive(
       $cacheDefault,
       [
           'adapter' => [
               'options' => [
                    'namespace' => 'weekly',
                   'ttl'       => 604800, // whole week
               ],
           ],
       ]
    ),
  ];

它在 zend 3 中运行良好。但是在更新到 Laminas 和 PHP8.1 后,我得到了这个错误

Laminas\ServiceManager\Exception\ServiceNotCreatedException

文件:

/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:620

消息:

Service with name "cache_instrument_manager_search" could not be created. Reason: Configuration must contain a "adapter" key.

我已经改成

return [

   'cache_instrument_manager_search' => [
       'adapter' => 'Memcached',
       'options' => ['ttl' => 3600],
       'plugins' => [
           [
               'name' => 'exception_handler',
               'options' => [
                   'throw_exceptions' => false,
                ],
            ],
        ],
    ]
];

但是还是有这个错误 Laminas\ServiceManager\Exception\ServiceNotFoundException

文件:

/project/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:557

消息:

Unable to resolve service "Memcached" to a factory; are you certain you provided it during configuration?

我需要帮助。我在 Laminas 中阅读了文档,但仍然无法解决这个问题。

【问题讨论】:

    标签: zend-framework config memcached laminas php-8.1


    【解决方案1】:

    我正在使用 Redis 缓存,我必须添加:

    'Laminas\Cache\Storage\Adapter\Redis'

    到我的 modules.config.php 文件

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 2017-04-05
      • 1970-01-01
      • 2016-04-23
      • 2012-06-14
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      相关资源
      最近更新 更多