[wp-hackers] get_users() exhausts memory with 'all_with_meta' argument
Nikola Nikolov
nikolov.tmw at gmail.com
Fri Jan 3 16:01:47 UTC 2014
Do you/they really need all of the meta fields for all users? Since WP_User
can load meta field values as properties of the user object( or by using
$user->get( $meta_key ) ), I don't see why you would need to load all of
the meta fields into the memory.
The problem here is because of the fact that they have lots of users(each
one with their own meta information), creating an array of objects with all
of this data just depletes the allocated memory for the PHP process.
So, while loading the meta values as properties of the object might end-up
slower(since I believe, you have to make a separate request to get each
field from the DB), it should in theory work.
They might want to get rid of the user objects that they no longer need -
so something like this:
foreach ( $users as $i => $user ) {
// Do something with the user object here
// Now get rid of the user object
unset( $users[ $i ] );
}
I'm saying they *might*, because they might have enough memory to handle
all user objects when they don't load all of the fields, but instead just
some of them.
Also, it might be a better alternative to create a script that would do
what they are trying to do in incremental steps(maybe 100, or 500, or
however many users work without exhausting the memory limit) instead of in
one big chunk.
On Fri, Jan 3, 2014 at 5:10 PM, Mike Walsh <mpwalsh8 at gmail.com> wrote:
> I am working with a couple users who use the Email Users plugin where
> memory is being exhausted when calling get_users() with the 'fields'
> argument set to 'all_with_meta'. In both cases, the sites have a large
> number of users (one has 13k, the other 4.5k). In both cases a call to
> get_users() without any arguments succeeds but fails when the
> 'all_with_meta' option is used.
>
> Anyone run into this before? If so, how did you resolve it?
>
> So this works:
>
> $u = get_users();
>
> But this fails:
>
> $u = get_users(array(fields => 'all_with_meta'));
>
> I've asked one user to do add the following to their wp-config.php to see
> if it makes a difference:
>
> define('WP_MEMORY_LIMIT', '512M');
>
> It may work for this site however I am not sure if it simply delays a
> future failure or actually fixes it (if it does at all).
>
> Mike
> --
> Mike Walsh - mpwalsh8 at gmail.com
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list