PHP8 - APCuIterator::__construct(): 正则表达式支持未启用,请为 APCuIterator 正则表达式支持启用 PCRE

问题描述

我已经将我们的 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 修复了它。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...