1

I have to perform actions on about 15000 users. I'm using a query to retrieve all uids, but the script crashes when using the user_load_multiple

$uids = db_select('users', 'u')
          ->fields('u', array('uid'))
          ->condition('u.status', '1', '=')
          ->execute()
          ->fetchCol();

$users = user_load_multiple($uids);

The script is executed every night, in order to find all users for which the field "Contact again on" (field_contact_on) is empty. If it is empty, we put todays date + 1 year.

Does anyone has a suggestion on how to make this more efficient.

Thanks !

3
  • 3
    Check mikeytown2's answer here: drupal.stackexchange.com/questions/129789/…. Same principle applies
    – Clive
    Commented Sep 17, 2014 at 19:33
  • I've pinged mikeytown2 and asked if he wouldn't mind posting the answer, don't just want to copy/paste if I can help it :)
    – Clive
    Commented Oct 3, 2014 at 19:29
  • I'm traveling for the next 2 days so feel free to copy/paste and link back to the original. Answering on a phone is hard
    – mikeytown2
    Commented Oct 3, 2014 at 22:40

1 Answer 1

0

I was running into this issue as well. I ended up using EntityFieldQuery to pull my nodes. Then also went into my php.ini file and set my resource limit params to what I have pasted below.

max_execution_time = 1024     ; Maximum execution time of each script, in seconds
max_input_time = 2048   ; Maximum amount of time each script may spend parsing request data
memory_limit = 5048M      ; Maximum amount of memory a script may consume (8MB)

I've included my php module code below for your reference as well.

// go through player names and search
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'content_type_name_to_pull')
  ->propertyOrderBy('title', 'ASC')
  ->propertyCondition('status', 1);

$result = $query->execute();

if (!empty($result['node'])) {
  $nids = array_keys($result['node']);
  $nodes = node_load_multiple($nids);

  foreach ($nodes as $node) {
    // do what you want with the node
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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