Zend Server升级后WordPress PHP内存耗尽错误排查求助
升级Zend Server后,WordPress网站频繁出现随机内部服务器错误,刷新几次即可恢复。WordPress的debug.log中记录的错误如下:
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 607631544 bytes) in C:\MyWebsite\htdocs\website.mywebsite.com\wp-content\plugins\cookie-notice\cookie-notice.php on line 1299
常规提升PHP内存上限的方案不适用,因为错误中尝试分配的内存量极大(甚至达数GB),页面理论上不会占用这么多内存。最初错误指向cookie-notice插件,但移除该插件后,错误又转向wp-mail-smtp插件,且均发生在static变量初始化的代码行。
cookie-notice插件相关代码(第1299行)
function Cookie_Notice() { static $instance; //THIS IS LINE 1299 // first call to instance() initializes the plugin if ( $instance === null || ! ( $instance instanceof Cookie_Notice ) ) $instance = Cookie_Notice::instance(); return $instance; }
移除插件后出现的错误
PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 4230139628 bytes) in C:\MyWebsite\htdocs\website.myWebsite.com\wp-content\plugins\wp-mail-smtp\wp-mail-smtp.php on line 55
wp-mail-smtp插件相关代码(第55行)
function wp_mail_smtp() { /** * @var \WPMailSMTP\Core */ static $core; //LINE 55 is here if ( ! isset( $core ) ) { $core = new \WPMailSMTP\Core(); } return $core; }
两次错误的栈追踪均显示调用链指向WordPress核心文件,目前问题疑似与static变量相关,请求排查可能的原因。
内容的提问来源于stack exchange,提问作者NL3294

