You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows环境XAMPP部署WordPress出现随机内存溢出问题排查

Troubleshooting Random "Out of Memory" Fatal Errors in wp-includes/wp-db.php (XAMPP + WordPress)

First off, let's work through this step by step—your ini settings look reasonable on paper, but random memory errors often boil down to hidden conflicts or unoptimized database operations. Here's what to check:

Verify PHP Memory Limit is Actually Being Applied

Sometimes XAMPP uses separate php.ini files for the web server and CLI, so your 2048M setting might not be active for WordPress. Create a file named phpinfo.php in your WordPress root with this code:

<?php phpinfo(); ?>

Access it via your browser (e.g., http://localhost/phpinfo.php) and search for memory_limit. Confirm it shows 2048M. If not, locate the correct php.ini file (the path will be listed at the top of the phpinfo page) and update it, then restart Apache.

Rule Out Plugin/Theme Conflicts

Random errors often trace back to poorly coded plugins or themes that leak memory, especially during database operations.

  • Disable all plugins and switch to a default theme like Twenty Twenty-Four. If the error stops, re-enable plugins one by one until you find the culprit. Backup/import plugins, analytics tools, or custom post type managers are common offenders.
  • If you can't access the admin area, rename the plugins folder in wp-content to plugins_old via File Explorer—this will disable all plugins instantly.

Since the error is in wp-db.php, the issue is likely tied to inefficient database queries or large result sets:

  • Enable WordPress debug logging to catch problematic queries. Add these lines to your wp-config.php (before the /* That's all, stop editing! Happy publishing. */ line):
    define('WP_DEBUG', true);
    define('WP_DEBUG_LOG', true);
    define('SAVEQUERIES', true);
    
    Check the wp-content/debug.log file after the error occurs. Look for long-running queries or repeated queries that fetch massive amounts of data (e.g., SELECT * FROM wp_posts without limits).
  • Optimize your database using phpMyAdmin (available via XAMPP's control panel). Select your WordPress database, go to the "Operations" tab, and run OPTIMIZE TABLE on all tables. This cleans up fragmented data and reduces memory overhead.
  • Check for corrupted tables: In phpMyAdmin, select all tables, choose "Check table" from the dropdown, and repair any tables marked as corrupted.

Analyze Error Logs for Exact Triggers

Your 2.24MB Apache error log probably has detailed stack traces that can pinpoint the exact code causing the memory leak. Look for lines like:

Fatal error: Out of memory (allocated 2097152000) (tried to allocate 4096 bytes) in C:/xampp/htdocs/wordpress/wp-includes/wp-db.php on line XYZ

Note the line number in wp-db.php and any preceding function calls. For example, if it's happening during a get_results() call, that means a query is returning way more data than needed—you'll want to modify that query to use pagination or limit the results.

Check System-Level Memory Constraints

Even if PHP's memory limit is set high, your Windows machine might not have enough available RAM to support it.

  • Open Task Manager when the error occurs and check the memory usage of httpd.exe (Apache) and php.exe processes. If they're eating up most of your system's RAM, close other resource-heavy apps or consider upgrading your RAM.
  • XAMPP's Apache might be configured to spawn too many child processes, leading to overall high memory usage. Open httpd.conf (in XAMPP's Apache config folder) and adjust MaxRequestWorkers—start with a lower number (like 20) if it's set too high, then restart Apache.

Enable PHP Garbage Collection

Add this line to your wp-config.php to force PHP's garbage collection to run more aggressively, which can free up unused memory:

ini_set('zend.enable_gc', 1);

Quick Wins

  • Clear any WordPress cache (if using a caching plugin) to eliminate stale, memory-heavy cached data.
  • Update WordPress, all plugins, and your theme to the latest versions—many memory leaks are fixed in newer releases.

内容的提问来源于stack exchange,提问作者OM The Eternity

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:11:47