【问题标题】:Migrating von APC to APCU in php application在 php 应用程序中将 von APC 迁移到 APCU
【发布时间】:2019-02-22 23:04:59
【问题描述】:

内容管理框架 MODX 提供了使用 APC 作为缓存引擎的选项。我发现我可以将其迁移到 APCu。

我复制并编辑了所有代码,因此我现在有了第二个选项,它提供 APCu 作为缓存引擎。由于我的 php 技能在过去几年中有所下降,我正在努力寻找正确的方法来重写构造函数。

原来的代码是这样的:

class xPDOAPCCache extends xPDOCache {
public function __construct(& $xpdo, $options = array()) {
    parent :: __construct($xpdo, $options);
    if (function_exists('apc_exists')) {
        $this->initialized = true;
    } else {
        $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOAPCCache[{$this->key}]: Error creating APC cache provider; xPDOAPCCache requires the APC extension for PHP, version 2.0.0 or later.");
    }
}
[...]

我是这样重写的:

class xPDOAPCuCache extends xPDOCache {
   public function __construct(& $xpdo, $options = array()) {
        parent :: __construct($xpdo, $options);
        if (function_exists('apcu_exists')) {
            $this->initialized = true;
        } else {
            $this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOAPCuCache[{$this->key}]: Error creating APCu cache provider; xPDOAPCuCache requires the APCu extension for PHP.");
        }
    }
    [...]

这是行不通的,因为 APCu 不采用与 APC 相同的参数。 (见http://php.net/manual/de/apciterator.construct.phphttp://php.net/manual/de/apcuiterator.construct.php

我需要如何编辑这个构造函数才能让我的 CMF 与 APCu 作为缓存引擎一起工作?

【问题讨论】:

    标签: php modx apc modx-revolution apcu


    【解决方案1】:

    您的代码示例似乎根本没有引用 APCIterator?所以很难说会发生什么变化。

    我建议你看看apcu_bc,它在APCu 之上提供了与APC API 的兼容层。我不确定迭代器具体是什么,但我已经成功使用这个包有一段时间了,直到我逐渐迁移到原生 APCu API。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      相关资源
      最近更新 更多