WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to store an array containing about 50000 keys and respective values to the user meta using update_user_meta. Since, this was only a test, I ran a for loop to generate the array.

$test = array ();
for ($i = 0; $i <= 50000; $i++) {
    $test[$i] = $i;
update_user_meta($user_id, 'test', $test);

I ended up getting the error WordPress database error: [MySQL server has gone away]. Eventually, I was able to get it working with an array size of 48000 keys. Since update_user_meta converts arrays to serialized data before storing, is there a limit to the serialized data that user meta or post metas can handle? Or does this happen due to some other issue?

I tried the timeout fix suggested here. But I am not sure if it is supposed to work for WP 3.3.1. or whether if at all it is solution to my problem.

Please note I am using a local dev install using MAMP.

share|improve this question
Currently, I have increased the max_allowed_packet size for MySQL to 5MB. This has given me the ability to store an array with 200K keys to user meta. However, Tom suggests an interesting solution of using custom user taxonomies. I need a solution that's scalable. I'd like to have opinion from others on which approach should be taken in this context. Saving an array as serialized data in user meta or custom user taxonomies? – John Apr 17 '12 at 22:53
up vote 2 down vote accepted

According to the DB schemea, the meta_value column is of type longtext, and that has a maximum size of 4GB, however you're unlikely to reach that.

Eitherway storing large quantities of data in a single field is bad both from a practical point of view, a performance point of view, and data storage.

I advise instead you use a custom taxonomy for this kind of data ( yes taxonomies aren't just for post objects )

share|improve this answer
Thx for the reply. The data I need to store to user meta would be done for each user registered on the site. In future the user base could climb to 100K users or more. Wouldn't saving the data as custom taxonomy for each user bloat the database? – John Apr 17 '12 at 19:44
No more than saving it as user meta, BUT, if you ever needed t do queries on that data it would be much much easier to do it using the taxonomy than to search through user meta – Tom J Nowell Apr 17 '12 at 20:51
After lot of deliberation I have finally understood the benefits of using user taxonomies for this need. I ended up creating a user taxonomy with the same name as the username of a User A. And all other users whose ID I earlier used to add to meta data of User A, I now add to the user taxonomy that was created as above. Please advise if this approach is correct? Secondly, I see wp_user_query class for querying users. Not sure how to make it work with user taxonomy. Could you please update your answer with an example on how to run queries to fetch users using user taxonomy? – John Apr 19 '12 at 16:57
A taxonomy is used to classify objects, or more specifically object IDs. Most people use this as in post IDs, and thus assume it means only post IDs. Please refer here: justintadlock.com/archives/2011/10/20/… – Tom J Nowell Apr 19 '12 at 17:19
There's also custom post types, where the term slug is the user login/user ID – Tom J Nowell Apr 19 '12 at 17:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.