performance icon indicating copy to clipboard operation
performance copied to clipboard

PHP Fatal error: Allowed memory size bytes exhausted

Open logut opened this issue 2 years ago • 1 comments

Bug Description

I'm trying to install the plugin on the network of a multiste install. When the plugin is enabled on some pages and only when I'm not authenticated part of the page is missing and in the wp-content/debug.log log the following errors apprears:

[30-Oct-2023 22:45:47 UTC] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 73728 bytes) in /var/www/wp-includes/functions.php on line 7030
[30-Oct-2023 22:45:47 UTC] PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes) in /var/www/wp-includes/class-wpdb.php on line 2425

Without the plugin enabled or when authenticated, Query Monitor shows a usage of ~15MB of memory.

Steps to reproduce

  1. Install the plugin
  2. Enable it
  3. Browse to concerned pages using an other browser

Additional Context

  • PHP Version: 8.1.25 php-fpm with memory_limit: 256M
  • Wordpress: 6.3.2
  • OS: Fedora 37
  • Browser: Chrome 118.0.5993.117
  • Plugin Version: 2.7.0
  • Device: Desktop

I suspect incompatibility with the custom theme or some plugins installed on the network but I don't know how to investigate more. Do you have an idea for the source of the bug ? Or how I could go on to find the source myself ?

logut avatar Oct 30 '23 23:10 logut

I added define('PERFLAB_DISABLE_SERVER_TIMING', true); in my wp-config.php, and it solved the error. What I have tried :

  • Set PHP memory_limit to 1G : just takes longer to crash
  • Disabling most of the plugins: error still there
  • Added in /wp-includes/functions.php at the beginning of function wp_debug_backtrace_summary the code $e = new \Exception; error_log('call of wp_debug_backtrace_summary : ' . $e->getTraceAsString()); to find why this function was called so many times when the crash occurs Looked for the most reoccurring non-Wordpress lines with sed 's/^#[0-9]\+ //' d.log |sort |uniq -c|sort -n (this is for 1 request)
...
    341 /var/www/wp-includes/class-wpdb.php(3146): wpdb->query()
    358 {main}
    358 /var/www/index.php(17): require('...')
    358 /var/www/wp-includes/class-wpdb.php(2263): wpdb->_do_query()
    358 /var/www/wp-includes/class-wpdb.php(2358): wpdb->get_caller()
  52975 /var/www/wp-content/plugins/performance-lab/server-timing/class-perflab-server-timing-metric.php(143): Perflab_Server_Timing_Metric->set_value()
  52975 /var/www/wp-content/plugins/performance-lab/server-timing/class-perflab-server-timing-metric.php(87): esc_html__()
  52975 /var/www/wp-content/plugins/performance-lab/server-timing/defaults.php(114): Perflab_Server_Timing_Metric->measure_after()
  52975 /var/www/wp-includes/class-wp-hook.php(324): {closure}()
  52975 /var/www/wp-includes/l10n.php(1306): get_template_directory()
  52975 /var/www/wp-includes/l10n.php(1331): _load_textdomain_just_in_time()
  52975 /var/www/wp-includes/l10n.php(185): get_translations_for_domain()
  52975 /var/www/wp-includes/l10n.php(330): translate()
  52975 /var/www/wp-includes/option.php(625): apply_filters()
  52975 /var/www/wp-includes/theme.php(319): get_option()
  52975 /var/www/wp-includes/theme.php(332): get_template()
  52977 /var/www/wp-includes/plugin.php(205): WP_Hook->apply_filters()
  53301 /var/www/wp-includes/option.php(164): wp_load_alloptions()

The loop looks like: extract_debug.log (there is >300 loops like this for 1 request) The loops seems to always go trough /var/www/wp-content/themes/adipso/archive-chef.php(9): get_site_url() the code for this <a href="<?php echo get_site_url(4); ?>" class="sub1">... </a> <a href="<?php echo get_site_url(3); ?>" class="sub3">...</a>

I don't understand what/if I got something misconfigured or how to go from there, do you have a lead ?

logut avatar Dec 25 '23 00:12 logut