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!