查询数据库时RAM占用过高引发5XX错误排查求助
问题:WordPress+LearnPress后台频繁出现内存耗尽导致的500错误
我运营的网站搭载WordPress及LearnPress LMS插件已一年,近1-2个月后台随机出现500错误,且频次逐渐增加。
错误日志详情
1. wp-db.php内存耗尽错误
错误信息:/wp-includes/wp-db.php第2128行:Allowed memory size of 536870912 bytes exhausted (tried to allocate 4096 bytes)
对应代码段:
// Return number of rows affected. $return_val = $this->rows_affected; } else { $num_rows = 0; if ( $this->use_mysqli && $this->result instanceof mysqli_result ) { 2128 while ( $row = mysqli_fetch_object( $this->result ) ) { $this->last_result[ $num_rows ] = $row; $num_rows++; } } elseif ( is_resource( $this->result ) ) { while ( $row = mysql_fetch_object( $this->result ) ) { $this->last_result[ $num_rows ] = $row; $num_rows++; } }
2. option.php内存耗尽错误
错误信息:/wp-includes/option.php第295行:Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 41943040 bytes)
对应代码段:
$alloptions = array(); foreach ( (array) $alloptions_db as $o ) { 295 $alloptions[ $o->option_name ] = $o->option_value; }
已尝试但无效的方案
- 提升PHP内存限制
- 迁移至VPS服务器
- 绕过Cloudflare
- 禁用所有插件
- 更新/降级PHP、WordPress及插件版本
- 回滚至1个月前的站点备份
当前推测
推测是数据库查询操作引发大量内存占用,但无法定位具体根源,希望找到排查和解决的方法。
内容的提问来源于stack exchange,提问作者Geekobit
相关产品推荐
相关产品推荐

