1

I'm a newer WP developer trying to wrap his head around how to store information in the options table to support a plugin that I am writing. Unfortunately, trying to UPDATE the options table is making my site crash due to exceeding memory limits.

The function below is from my class which needs the ability to update the values of the options. I wrote this so that I could overwrite the value of any single key/value pair in the options array.

private function my_update_option($str_key, $str_value) {
    $arr_options = get_option( 'my_options' );
    $arr_options[$str_key] = $str_value;
   update_option( 'my_options', $arr_options );
}

WITHOUT the update_option() function call, one of my memory plugins says that I am using 64.01 of 128M of the allowed PHP memory limits on the server. However, as soon as I use the update_option() function, the site crashes with the following error.

PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 17652686 bytes) in [.......]

I know that I must be doing something horribly wrong here, but based on everything that I have read before I feel like this should work. Why on earth does this function call suddenly add over 100M of required memory usage?

I'm not interested in "just raise your memory limit" to solve the problem - I want to know WHY this is crashing so that I can actually write it better and prevent it from using so much memory. Thanks!

  • 2
    Have you tried var_dumping the contents of $arr_options? – Dan Mar 27 '14 at 19:41
  • 2
    I'm curious why whatever you're doing is requiring 64 in the first place. – Andrew Bartel Mar 27 '14 at 19:56
  • @Andrew, I stripped everything down to check for you, since it's a site just for dev it's very bare-bones. Running 3.8.1 on a stock underscores theme, I'm showing 42M usage with "TPC! Memory Usage" being the ONLY plugin enabled. That number jumps to 69M by enabling the plugin I'm working on (which already tells me I'm doing something wrong :)) – Dave McHale Mar 30 '14 at 20:59
  • 1
    @Dan, thanks for the basic suggestion (since sometimes those are the best, like in this case). While I thought I knew what was in my options table, there was a variable being saved in some awful format and the serialized data said the saved string was 17M+ characters long. Guess I know where to start fixing things - thanks! – Dave McHale Mar 30 '14 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.