问题描述
我已经将我们的 Docker 镜像从 PHP7.4 升级到 PHP8,现在每次请求都会出现这个错误:
APCuIterator::__construct(): Regular expressions support is not enabled,please enable PCRE for APCuIterator regex support.
我们正在使用 Symfony,它正在调用 new APCuIterator()
。为了单独重现这一点,我为 CLI 启用了 apcu
,然后自己调用了构造函数:
$ vim /etc/php/8.0/mods-available/apcu.ini
apc.enable_cli=1
$ php -a
Interactive mode enabled
php > new APCuIterator('whatever');
PHP Fatal error: APCuIterator::__construct(): Regular expressions support is not enabled,please enable PCRE for APCuIterator regex support. in php shell code on line 1
虽然启用了 PCRE,但 preg_match()
可以正常工作。
禁用 APCu 似乎可以解决问题,但这不是“解决方案”:
# /etc/php/8.0/mods-available/apcu.ini
# extension=apcu.so <-- comment this out
我很困惑,因为在 Google 上几乎找不到与此错误消息相符的内容。
解决方法
原来是版本问题。我安装的 APCu 5.1.17
失败了。
升级到 APCu 5.1.20
修复了它。