Title: 502 Timeout Errors with many users
Last modified: April 16, 2019

---

# 502 Timeout Errors with many users

 *  [info2grow](https://wordpress.org/support/users/info2grow/)
 * (@info2grow)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/)
 * Just curious if it’s possible to stop the plugin from looping through all users
   when loading the Send to Groups screen. We have 5000+ users and just want to 
   send to a small group of them using the ITThinx Groups integration but it seems
   that in order to build the page the plugin is looping through all users when 
   it might be able to get away with just querying users based on a group selection
   when send is hit.
 * I would love to help if you can point me in the right direction. I would also
   be happy to pay you for this modification so we can continue using this helpful
   plugin!
    -  This topic was modified 7 years, 1 month ago by [info2grow](https://wordpress.org/support/users/info2grow/).

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [info2grow](https://wordpress.org/support/users/info2grow/)
 * (@info2grow)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11436652)
 * so far I’ve narrowed it to integration/itthinx-groups.php line 87
 * // Make sure the list of IDs accounts for the Email Users settings for email
   
   $ids = mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter) ;
 * If I comment out that line the send to groups page loads…
 *  Thread Starter [info2grow](https://wordpress.org/support/users/info2grow/)
 * (@info2grow)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11439163)
 * Digging deeper it’s actually with get_users is called in email_users.php on line
   1436 that is actually stopping the initial page load of Send to Group(s). Obviously
   that needs to be there but does it need to happen on page load specifically for
   send to groups?
 * To be clear when either of these lines are not commented out the send to groups
   page will not load at all and I get a 502. It looks like the code may be looping
   through all groups and assigning the associated ids of users in each those groups
   on page load. Perhaps we can just query users of the chosen groups after Send
   Email is pressed?
 *  Plugin Author [Mike Walsh](https://wordpress.org/support/users/mpwalsh8/)
 * (@mpwalsh8)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11439576)
 * I apologize for the delayed response. I am out of the country this week on vacation
   and have nothing but an iPad with me so looking at this issue is a challenge.
 * 5000 users is a lot so it doesn’t surprise me you are seeing a problem. A number
   of years ago I had a similar problem with Send to Users with someone who had 
   8000+ users on the site. The solution was to break the query up into chunks. 
   I cannot recall it I ever added the same solution to groups or not, based on 
   your description I am guessing I did not.
 * I won’t be back in the US until Sunday and I suspect catching up on work email
   will take me a day or two. I will try to look into this next week when I am home.
   If you find a solution and want to send me a patch, I’d be happy to consider 
   incorporating it.
 *  Thread Starter [info2grow](https://wordpress.org/support/users/info2grow/)
 * (@info2grow)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11440201)
 * Thanks Mike! I think I have it sorted…
 * in mail-users/integration/itthinx-groups.php
 * It looks like it was the code that checks for empty groups.
 * In function mailusers_get_itthinx_groups
    1. comment out line 52 as we are already getting the ids on send
    2. Remove the if clause from line 54 that checks for empty groups
    3. We still need a check for empty groups inside function mailusers_get_recipients_from_itthinx_groups_group
       on line 80 so I added another clause. It works but there may be a better way.
    4. `if ((is_array($group) || is_object($group)) && $group->__get('users')) {`
    5. then we need to check if the ids array is empty before calling mailusers_get_recipients_from_ids
       on line 88
    6.     ```
             if(!empty($ids)){
               //  Make sure the list of IDs accounts for the Email Users settings for email
               $ids = mailusers_get_recipients_from_ids($ids, $exclude_id, $meta_filter) ;
             }
           ```
       
 * Worked for a small group, now I am about to try a group of 750…
 *  Thread Starter [info2grow](https://wordpress.org/support/users/info2grow/)
 * (@info2grow)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11440450)
 * Update no 502 loading the page so the code above addressed that however when 
   sending to 750 users I got 502 partway through. 293 emails were sent successfully.
 * We host with WPEngine and use Mailgun (and the Mailgun plugin) to handle the 
   actual sending of the emails.
 * in email-users.php I have number set to 100 on line 1353 if that helps
 *     ```
       //  Set up the arguments for get_users()
   
           $args = array_merge($args, array(
               'exclude' => array($exclude_id),
               //'fields' => array('ID', 'display_name', 'user_email'),
               'fields' => 'all',
               'offset' => '0',
               'number' => '100',
           )) ;
       ```
   
    -  This reply was modified 7 years, 1 month ago by [info2grow](https://wordpress.org/support/users/info2grow/).
    -  This reply was modified 7 years, 1 month ago by [info2grow](https://wordpress.org/support/users/info2grow/).
 *  [cztxjv](https://wordpress.org/support/users/cztxjv/)
 * (@cztxjv)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-11727802)
 * [@mpwalsh8](https://wordpress.org/support/users/mpwalsh8/) Update? I’m having
   the same issue on my site with 2000+ users. It takes a good 1 minute before it
   loads the page. I’m fearing if this continues It will stop working altogether.
 *  [louisewhitehurst](https://wordpress.org/support/users/louisewhitehurst/)
 * (@louisewhitehurst)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-12056310)
 * What about adding custom filters to loops by installing respective plugins or
   setting the group parameter? Though, this can be only a temporary solution.
    
   [https://wordpress.org/support/topic/502-timeout-errors-with-many-](https://wordpress.org/support/topic/502-timeout-errors-with-many-users)
   [essays](https://theessayservice.org/)
 *  Plugin Author [Mike Walsh](https://wordpress.org/support/users/mpwalsh8/)
 * (@mpwalsh8)
 * [6 years, 7 months ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-12061727)
 * As evidence by my lack of response to these questions, I have not really had 
   any time to look into these problem reports. A lot of things have changed for
   me which really limits how much (little? none?) time I can devote to this plugin(
   and others too).
 * I used WordPress extensively for a number of projects I volunteered on (school,
   sports, etc.) but with my kids all out of High School, I am not doing that any
   longer. All of those projects have been handed over to the next group of parent
   volunteers, some stuck with WordPress, some went other directions. My regular
   day job, the one which pays the bills, has also changed dramatically in the past
   couple years as well. I am busier and traveling much more and I don’t expect 
   that to change any time soon.
 * If someone is interested in taking over development and maintenance of Email 
   Users, let me know and we can figure something out. I am not the original author,
   I picked up responsibility in much the same way from the original author who 
   found themselves in a similar situation I find myself in now.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘502 Timeout Errors with many users’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/email-users_a0e0cf.svg)
 * [Email Users](https://wordpress.org/plugins/email-users/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/email-users/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/email-users/)
 * [Active Topics](https://wordpress.org/support/plugin/email-users/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/email-users/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/email-users/reviews/)

 * 8 replies
 * 4 participants
 * Last reply from: [Mike Walsh](https://wordpress.org/support/users/mpwalsh8/)
 * Last activity: [6 years, 7 months ago](https://wordpress.org/support/topic/502-timeout-errors-with-many-users/#post-12061727)
 * Status: not resolved