How do I show a message about the currently executed operation? I have created a batch, and it's working, but I want to control the messaging a little better. I would like to give the user some feedback about the currently executing operation, other than just letting them know that it has completed.

Here is what I am attempting to do, but it is still executing sleep(5) before updating the message.

function batch_callback(&amp;$context) {

  // set up message for batch operation
  if (empty($context['sandbox'])) {

    $context['message']  = t('Pre-execution message...');
    $context['finished'] = FALSE;

    // put something in sandbox (doesn't matter what)
    $context['sandbox']['step'] = 1;

    return;
  }

  sleep(5);

  $context['finished'] = TRUE;
}


So, how do I set a pre-execution batch message?
The message will be shown just when the batch callback returns. If your intent is pausing the batch operations to let users see the pre-execution message, I would rather use the following code.

function batch_callback(&amp;$context) {
  if (empty($context['sandbox'])) {
    $context['message']  = t('Pre-execution message...');
    $context['finished'] = FALSE;
    $context['sandbox']['step'] = 1;

    return;
  }
  elseif ($context['sandbox']['step'] == 1) {
    sleep(5);
  }
  // Do your operations.
}


You could also set the progress message using $batch_definition['progress_message'] (where $batch_definition is the value passed to batch_set(), but that just gets @current, @remaining, @total, @percentage, @estimate and @elapsed as placeholders. You could not use it to show, for example, the title of the node being processed, since it doesn't allow to use a custom placeholder. It is used more for messages like Completed @current of @total.