从 zend3 更新到 PHP 8.1 后 Laminas 缓存配置问题

发布于 2025-01-12 17:01:29 字数 2249 浏览 1 评论 0原文

我从事的项目最近从 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 的文档,但仍然无法解决这个问题。

I work on a project which is recently updated to Laminas and PHP 8.1 from Zend3 and PHP 7.4.

in config/autoload/global.php

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

and this is 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
               ],
           ],
       ]
    ),
  ];

It worked well in zend 3. but after updating to Laminas and PHP8.1 I got this error

Laminas\ServiceManager\Exception\ServiceNotCreatedException

File:

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

Message:

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

I have changed it to

return [

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

But Still has this error
Laminas\ServiceManager\Exception\ServiceNotFoundException

File:

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

Message:

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

I need help. I read documents in Laminas but still could not solve this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2025-01-19 17:01:29

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

'Laminas\Cache\Storage\Adapter\Redis'

到我的 modules.config.php 文件中

I'm using Redis Cache and I had to add:

'Laminas\Cache\Storage\Adapter\Redis'

to my modules.config.php file

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文