function drush_backend_invoke_concurrent

8.0.x backend.inc drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL)
6.x backend.inc drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL)
7.x backend.inc drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL)
5.x backend.inc drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL)
master backend.inc drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL)

Execute a new local or remote command in a new process.

n.b. Prefer drush_invoke_process() to this function.

Parameters

invocations: An array of command records to exacute. Each record should contain: 'site': An array containing information used to generate the command. 'remote-host' Optional. A remote host to execute the drush command on. 'remote-user' Optional. Defaults to the current user. If you specify this, you can choose which module to send. 'ssh-options' Optional. Defaults to "-o PasswordAuthentication=no" '#env-vars' Optional. An associative array of environmental variables to prefix the Drush command with. 'path-aliases' Optional; contains paths to folders and executables useful to the command. '%drush-script' Optional. Defaults to the current drush.php file on the local machine, and to simply 'drush' (the drush script in the current PATH) on remote servers. You may also specify a different drush.php script explicitly. You will need to set this when calling drush on a remote server if 'drush' is not in the PATH on that machine. 'command': A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'. 'args': An array of arguments for the command. 'options' Optional. An array containing options to pass to the remote script. Array items with a numeric key are treated as optional arguments to the command. 'backend-options': Optional. Additional parameters that control the operation of the invoke. 'method' Optional. Defaults to 'GET'. If this parameter is set to 'POST', the $data array will be passed to the script being called as a JSON encoded string over the STDIN pipe of that process. This is preferable if you have to pass sensitive data such as passwords and the like. For any other value, the $data array will be collapsed down into a set of command line options to the script. 'integrate' Optional. Defaults to TRUE. If TRUE, any error statuses will be integrated into the current process. This might not be what you want, if you are writing a command that operates on multiple sites. 'log' Optional. Defaults to TRUE. If TRUE, any log messages will be integrated into the current process. 'output' Optional. Defaults to TRUE. If TRUE, output from the command will be synchronously printed to stdout. 'drush-script' Optional. Defaults to the current drush.php file on the local machine, and to simply 'drush' (the drush script in the current PATH) on remote servers. You may also specify a different drush.php script explicitly. You will need to set this when calling drush on a remote server if 'drush' is not in the PATH on that machine. 'dispatch-using-alias' Optional. Defaults to FALSE. If specified as a non-empty value the drush command will be dispatched using the alias name on the command line, instead of the options from the alias being added to the command line automatically.

common_options: Optional. Merged in with the options for each invocation.

backend_options: Optional. Merged in with the backend options for each invocation.

default_command: Optional. Used as the 'command' for any invocation that does not define a command explicitly.

default_site: Optional. Used as the 'site' for any invocation that does not define a site explicitly.

context: Optional. Passed in to proc_open if provided.

Return value

If the command could not be completed successfully, FALSE. If the command was completed, this will return an associative array containing the data from drush_backend_output().

2 calls to drush_backend_invoke_concurrent()
drush_invoke_process in includes/command.inc
Invoke a command in a new process, targeting the site specified by the provided site alias record.
make_projects in commands/make/make.drush.inc
Process all projects specified in the make file.

File

includes/backend.inc, line 710
Drush backend API

Code

function drush_backend_invoke_concurrent($invocations, $common_options = array(), $common_backend_options = array(), $default_command = NULL, $default_site = NULL, $context = NULL) {
  $index = 0;

  // Slice and dice our options in preparation to build a command string
  $invocation_options = array();
  foreach ($invocations as $invocation) {
    $site_record = isset($invocation['site']) ? $invocation['site'] : $default_site;
    // NULL is a synonym to '@self', although the latter is preferred.
    if (!isset($site_record)) {
      $site_record = '@self';
    }
    // If the first parameter is not a site alias record,
    // then presume it is an alias name, and try to look up
    // the alias record.
    if (!is_array($site_record)) {
      $site_record = drush_sitealias_get_record($site_record);
    }
    $command = isset($invocation['command']) ? $invocation['command'] : $default_command;
    $args = isset($invocation['args']) ? $invocation['args'] : array();
    $command_options = isset($invocation['options']) ? $invocation['options'] : array();
    $backend_options = isset($invocation['backend-options']) ? $invocation['backend-options'] : array();
    // If $backend_options is passed in as a bool, interpret that as the value for 'integrate'
    if (!is_array($common_backend_options)) {
      $integrate = (bool) $common_backend_options;
      $common_backend_options = array('integrate' => $integrate);
    }

    $command_options += $common_options;
    $backend_options += $common_backend_options;

    $backend_options = _drush_backend_adjust_options($site_record, $command, $command_options, $backend_options);
    $backend_options += array(
      'drush-script' => NULL,
    );

    // Insure that contexts such as DRUSH_SIMULATE and NO_COLOR are included.
    $command_options += _drush_backend_get_global_contexts($site_record);

    // Add in command-specific options as well
    $command_options += drush_command_get_command_specific_options($site_record, $command);

    // If the caller has requested it, don't pull the options from the alias
    // into the command line, but use the alias name for dispatching.
    if (!empty($backend_options['dispatch-using-alias']) && isset($site_record['#name'])) {
      list($post_options, $commandline_options, $drush_global_options) = _drush_backend_classify_options(array(), $command_options, $backend_options);
      $site_record_to_dispatch = '@' . ltrim($site_record['#name'], '@');
    }
    else {
      list($post_options, $commandline_options, $drush_global_options) = _drush_backend_classify_options($site_record, $command_options, $backend_options);
      $site_record_to_dispatch = '';
    }
    if (array_key_exists('backend-simulate', $backend_options)) {
      $drush_global_options['simulate'] = TRUE;
    }
    $site_record += array(
      'path-aliases' => array(),
      '#env-vars' => array(),
    );
    $site_record['path-aliases'] += array(
      '%drush-script' => $backend_options['drush-script'],
    );

    $site = (array_key_exists('#name', $site_record) && !array_key_exists($site_record['#name'], $invocation_options)) ? $site_record['#name'] : $index++;
    $invocation_options[$site] = array(
      'site-record' => $site_record,
      'site-record-to-dispatch' => $site_record_to_dispatch,
      'command' => $command,
      'args' => $args,
      'post-options' => $post_options,
      'drush-global-options' => $drush_global_options,
      'commandline-options' => $commandline_options,
      'command-options' => $command_options,
      'backend-options' => $backend_options,
    );
  }

  // Calculate the length of the longest output label
  $max_name_length = 0;
  $label_separator = '';
  if (!array_key_exists('no-label', $common_options) && (count($invocation_options) > 1)) {
    $label_separator = array_key_exists('label-separator', $common_options) ? $common_options['label-separator'] : ' >> ';
    foreach ($invocation_options as $site => $item) {
      $backend_options = $item['backend-options'];
      if (!array_key_exists('#output-label', $backend_options)) {
        if (is_numeric($site)) {
          $backend_options['#output-label'] = ' * [@self.' . $site;
          $label_separator = '] ';
        }
        else {
          $backend_options['#output-label'] = $site;
        }
        $invocation_options[$site]['backend-options']['#output-label'] = $backend_options['#output-label'];
      }
      $name_len = strlen($backend_options['#output-label']);
      if ($name_len > $max_name_length) {
        $max_name_length = $name_len;
      }
      if (array_key_exists('#label-separator', $backend_options)) {
        $label_separator = $backend_options['#label-separator'];
      }
    }
  }
  // Now pad out the output labels and add the label separator.
  $reserve_margin = $max_name_length + strlen($label_separator);
  foreach ($invocation_options as $site => $item) {
    $backend_options = $item['backend-options'] + array('#output-label' => '');
    $invocation_options[$site]['backend-options']['#output-label'] = str_pad($backend_options['#output-label'], $max_name_length, " ") . $label_separator;
    if ($reserve_margin) {
      $invocation_options[$site]['drush-global-options']['reserve-margin'] = $reserve_margin;
    }
  }

  // Now take our prepared options and generate the command strings
  $cmds = array();
  foreach ($invocation_options as $site => $item) {
    $site_record = $item['site-record'];
    $site_record_to_dispatch = $item['site-record-to-dispatch'];
    $command = $item['command'];
    $args = $item['args'];
    $post_options = $item['post-options'];
    $commandline_options = $item['commandline-options'];
    $command_options = $item['command-options'];
    $drush_global_options = $item['drush-global-options'];
    $backend_options = $item['backend-options'];
    $is_remote = array_key_exists('remote-host', $site_record);
    $is_different_site = $is_remote || (isset($site_record['root']) && ($site_record['root'] != drush_get_context('DRUSH_DRUPAL_SITE_ROOT')));
    $os = drush_os($site_record);
    // If the caller did not pass in a specific path to drush, then we will
    // use a default value.  For commands that are being executed on the same
    // machine, we will use DRUSH_COMMAND, which is the path to the drush.php
    // that is running right now.  For remote commands, we will run a wrapper
    // script instead of drush.php -- drush.bat on Windows, or drush on Linux.
    $drush_path = $site_record['path-aliases']['%drush-script'];
    if (!$drush_path && !$is_remote && $is_different_site) {
      $drush_path = find_wrapper_or_launcher($site_record['root']);
    }
    $env_vars = $site_record['#env-vars'];
    $php = array_key_exists('php', $site_record) ? $site_record['php'] : (array_key_exists('php', $command_options) ? $command_options['php'] : NULL);
    $drush_command_path = drush_build_drush_command($drush_path, $php, $os, $is_remote, $env_vars);
    $cmd = _drush_backend_generate_command($site_record, $drush_command_path . " " . _drush_backend_argument_string($drush_global_options, $os) . " " . $site_record_to_dispatch . " " . $command, $args, $commandline_options, $backend_options) . ' 2>&1';
    $cmds[$site] = array(
      'cmd' => $cmd,
      'post-options' => $post_options,
      'backend-options' => $backend_options,
    );
  }

  return _drush_backend_invoke($cmds, $common_backend_options, $context);
}