记遇到的一个php坑
程序员文章站
2022-04-14 23:01:20
最近对项目的一个高访问量业务接口进行功能扩展,上线一段时间后,服务器cpu load突然飙升,并出现大量502。一开始找运维查看日志,并没有看是什么问题,后来发现别的部门项目之前也遇到类似的问题,原来是触发了一个php bug。此bug触发条件是:PHP版本低于5.6.12、开启opcache、高访 ......
最近对项目的一个高访问量业务接口进行功能扩展,上线一段时间后,服务器cpu load突然飙升,并出现大量502。一开始找运维查看日志,并没有看是什么问题,后来发现别的部门项目之前也遇到类似的问题,原来是触发了一个php bug。此bug触发条件是:PHP版本低于5.6.12、开启opcache、高访问量、定义 const 常量并且为二维数组,刚好满足这些条件,真心泪奔。。升级服务器上面的PHP版本之后,就没有再出现了。重启php-fpm,可以一段时间内不会出现502,应急处理之用。
php bug:https://bugs.php.net/bug.php?id=70601
const REPLACEMENTS_PASS_1 = [ "\x00" => "", "\x01" => "", "\x02" => "", "\x03" => "", "\x04" => "", "\x05" => "", "\x06" => "", "\x07" => "", "\x08" => "", "\x0B" => "", "\x0C" => "", "\x0D" => "", "\x0E" => "", "\x0F" => "", "\x10" => "", "\x11" => "", "\x12" => "", "\x13" => "", "\x14" => "", "\x15" => "", "\x16" => "", "\x17" => "", "\x18" => "", "\x19" => "", "\x1A" => "", "\x1B" => "", "\x1C" => "", "\x1D" => "", "\x1E" => "", "\x1F" => "", "\x7F" => "", ]; public function __construct() { echo strtr("abcd", self::REPLACEMENTS_PASS_1); }