how to get a list of all users on the elgg website?

I am using get_entities('user') to get a list of all users on the website, but it results to only 10 entities as there is a limit parameter.  I tried simple workaround with

specifying unlimited results
               $entities = get_entities('user', "", 0, "", 0, 0);
which caused php to run out of memory on deployed machine.

I tried some bigger but finite limit and my gateway timed out.

So what is the correct solution? I guess running it every 10 minutes for
just five or ten people and keeping offset stored somewhere. Like first
time it gets run it will be
               $entities = get_entities('user', "", 0, "", 5, 0);
you store that you ended up with 5 and next time, you'll run
               $entities = get_entities('user', "", 0, "", 5, 5);
and so long until you'll process all users and start from the beginning. Is there a better solution? Plz help.

  • Displaying all users without pagination is a bad idea. We tried this at a client's insistence and performance was terrible by the time the site hit a couple hundred users. Caching improvements are on the way which can help, but your best bet is to use elgg_get_entities with a callback that generates markup directly from the returned rows (replace the "callback" option).

  • ok so you mean, If i set the callback option, 

    elgg_get_entities
          (
              'types'                    =>    'user',
              ,'callback'                => 'my_get_entity_callback'
          )

    function my_get_entity_callback($one_data_row)
    {
        //perform my job
    }

    using function my_get_entity_callback, i'll be able to process all user entities, one at a time? I'm sorry i might be entirely wrong, but would like some help :)

  • elgg_get_entities(array('types'=>'user','callback'=>'my_get_entity_callback'));

    function my_get_entity_callback($one_data_row)

    {

        print_r($one_data_row);

        echo '<br>';

    }

    to test, this is actually what I did , just to see if the results are actually printed. still i get only 10 results.

  • If you don't pass the "limit" parameter the function will still default to maximum of 10 results. So add the parameter and set its value to false:

    elgg_get_entities(array(
        'types' => 'user',
        callback' => 'my_get_entity_callback'
        'limit' => false,
    ));

  • I'd look into the lorea infinite_scroll plugin and apply that technique to this page. For example, load about 5 pages worth of names then add another 5 when the user has scrolled into page 3. Otherwise you will start to run into long page load times.

    Or better, give the user the total user count and a choice of how many to display on each page with a sensible default.

  • Steve actually I am trying to build a karma plugin for a website. the core of this plugin is a cron script that fetches user activities on various places. so i need email id, twitter nick etc for each user on the website for which first i need all user entities to go ahead with retrieving furhter info. So will Juho's solution work on the deployed machine where there are thousands of users?

  • How about limiting the query only to few users but running the cron script more often (for example every hour)? During the cron script, save the time of the last run as metadata. Then use this metadata to order the query and get the users who have been the longest without updating.

    function my_get_entity_callback($one_data_row) {
        if (update_karma()) {
            // Karma was succesfully updated. Save the time.
            $user->karma_update_time = time();
        }
    }

    Then use this to get the users:

    elgg_get_entities_from_metadata(array(
        'types' => 'user',
        'callback' => 'my_get_entity_callback',
        'limit' => '20',
        'metadata_names' => 'karma_update_time',
        'order_by_metadata' => array(
            'name' => 'karma_update_time',
            'direction' => ASC,
            'as' => integer
        )
    ));

    Now you have 20 users who have been the longest without getting their karma updated.

    Note that this query only works with users who already have the "karma_update_time" saved in database. So you must first do the same with elgg_get_entities() and add the metadata for each user.

    Or if there aren't users yet, create a functionality that adds this metadata automatically when new user account is created.

  • There is a code snippet already available for it here. Try to search for get entities with out metadata. You are looking exactly for the same. Its from matt. 

  • Could you please pass me the link if you found it. I was unable to :(