间歇性 PHP 抽象类错误 [英] Intermittent PHP Abstract Class Error

查看:27
本文介绍了间歇性 PHP 抽象类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此挣扎了一段时间,但无法弄清楚,也许其他人有或者这里有 Slim、PHP、Apache 等更深层次的问题.在工作了几个小时之后,我的 Slim 安装将开始在所有路线上提供此信息:

<块引用>

致命错误:Slim\Collection 类包含 1 个抽象方法,因此必须在 F:\Projects\example\server\vendor\slim\slim\Slim\Collection 中声明为抽象或实现其余方法 (IteratorAggregate::getIterator).php 第 21 行

令人恼火的是,如果我重新启动 Apache,这个问题就会消失.(反正几个小时.)

我在两年前有人遇到类似问题的地方发现了这个,帮助他们的人在没有实际帮助的情况下纠缠他们:https://community.apachefriends.org/viewtopic.php?p=250966&sid=96ef58aaeb7fe142a7dcdfd506a8683f

我尝试彻底擦除并安装我的 composer vendor 目录.这不能解决它.我可以清楚地看到 getIterator 在错误消息中的文件中按预期实现.

PHP 版本 7.0.12,Windows 7,x86 PHP 构建

它在几个小时后再次发生,并带有不同但相似的错误消息:

<块引用>

致命错误:Pimple\Container 类包含 1 个抽象方法,因此必须声明为抽象方法或在 F:\Projects\example\server\vendor\pimple\pimple\src\Pimple 中实现其余方法 (ArrayAccess::sqlserver)\Container.php 第 34 行

这个问题有一个类似的问题,并通过重新启动 PHP 来解决"它,但这显然不是一个实际的解决方案,而且我没有启用 opcache:PHP 7, Symfony 3: Fatal error 1 抽象方法,因此必须声明为抽象或实现其余方法

有什么猜想吗?请记住:此消息位于我未编写的文件中,并在 Apache 重新启动时消失.PHP 7 是否有一些缓存会导致这种情况?

编辑 3/10/17:

是的,我已经和 Slim 开了一张票.我也在非超薄文件(Pimple)中看到过,所以我认为这不是超薄问题.https://github.com/slimphp/Slim/issues/2160

正如我所说,我的 opcache 已关闭.我已经在 php.ini 文件和查看 phpinfo() 中确认这是真的.

解决方案

我想你遇到了 这个 opcache 错误.这不是完全相同的情况,但可能相关.

<块引用>

在调用 opcache_reset() 函数后,我们遇到了一些奇怪的错误.它在服务器上随机发生(400 台服务器中的 10 台)

某些字母 a 被其他字母替换,Class 似乎已经声明了..等

在 opcache_reset() 之后触发的错误示例:

  • PHP 致命错误:XXX 类包含 1 个抽象方法,因此必须声明为抽象方法或实现其余方法(YYY::funczzz) 在第 20 行的/dir/dir/x.php

票已关闭,因为开发人员没有足够的信息来重现它.如果你能想出最小的可重复案例,我建议报告.创建一个非常小的 Slim 应用程序,然后使用 JMeter 或其他工具发出许多请求.发布您的发现.

与此同时,唯一的解决方法可能是关闭 php.ini 中的 opcache:

opcache.enable=0

当然,这会严重影响性能.在修复之前,您必须在性能或定期重新启动 Apache 之间做出选择.

如果关闭缓存不起作用,那么我能想到的唯一原因是操作码编译器的间歇性问题.缓存与否编译版本中必须有错误.如果这是原因,则与 PHP 开发人员开具可重现的票证或自行调试 PHP 源代码将是唯一的出路.

I've been fighting this for a bit, and can't figure it out, maybe someone else has or maybe there's a deeper issue here with Slim, PHP, Apache etc. After working just fine for hours, my Slim install will start giving this on all routes:

Fatal error: Class Slim\Collection contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (IteratorAggregate::getIterator) in F:\Projects\example\server\vendor\slim\slim\Slim\Collection.php on line 21

Maddeningly this issue goes away if I restart Apache. (For a few hours anyway.)

I found this where someone had a similar problem two years ago, and the person helping badgered them without actually assisting at all: https://community.apachefriends.org/viewtopic.php?p=250966&sid=96ef58aaeb7fe142a7dcdfd506a8683f

I've tried doing a clean wipe and install of my composer vendor directory. This doesn't fix it. I can clearly see that getIterator is implemented as expected in the file in the error message.

PHP Version 7.0.12, Windows 7, x86 PHP Build

It happened again after a few hours, with a different but similar error message:

Fatal error: Class Pimple\Container contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (ArrayAccess::sqlserver) in F:\Projects\example\server\vendor\pimple\pimple\src\Pimple\Container.php on line 34

This question has a similar problem and "solves" it by restarting PHP, but that clearly isn't an actual solution, and I don't have opcache enabled: PHP 7, Symfony 3: Fatal error 1 abstract method and must therefore be declared abstract or implement the remaining methods

Any guesses? Remember: This message is in files I didn't write, and goes away on Apache restart. Is there some caching with PHP 7 that would cause this?

Edit 3/10/17:

Yes, I've opened a ticket with Slim. I also saw it in a non-slim file (Pimple) so I don't think it is a Slim issue. https://github.com/slimphp/Slim/issues/2160

As I said, my opcache is off. I've confirmed this is true both in the php.ini file and looking at phpinfo().

解决方案

I think you've run into this opcache bug. This isn't exactly the same situation but probably related.

After calling opcache_reset() function we encounter some weird errors. It happens randomly on servers (10 of 400 servers production)

Some letter a replaced by others, Class seems to be already declared.. etc

Example of errors triggered after opcache_reset():

  • PHP Fatal error: Class XXX contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (YYY::funczzz) in /dir/dir/x.php on line 20

The ticket is closed because the developers don't have enough information to reproduce it. If you could come up with the smallest reproducible case I recommend reporting it. Create a very small Slim app and then use JMeter or another tool to make many requests. Post your findings.

Meanwhile the only workaround might be to turn off opcache in php.ini:

opcache.enable=0

Of course this will drastically hurt performance. Until it's fixed you'll have to choose between performance or periodically restarting Apache.

If turning the cache off doesn't work then the only cause I could think of is an intermittent problem with the opcode compiler. Cached or not the compiled version must have an error in it. Opening a reproducible ticket with the PHP devs or debugging the PHP source yourself would be the only way forward if this is the cause.

这篇关于间歇性 PHP 抽象类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆