Ok I have been working with the batch API and I have one working successfully now I would like to run another batch after the first one.

batch_set says I can do this:

  array('my_function_1', array($arg1)),
  array('my_function_2', array($arg2_1, $arg2_2)),

I am trying this, but it isn't running the second function:

$batch['operations'][] = array('test_function1', array($new_node), array('test_function2'), array($new_node)); 

Any ideas on how to run the second function?

1 Answer 1


Using more than one function for a batch surely works, as one of the test functions for the batch API contains the following call.


_batch_test_batch_3() contains the following code.

  // Ensure the batch takes at least two iterations.
  $total = 10;
  $sleep = (1000000 / $total) * 2;

  $operations = array();
  for ($i = 1; $i <= round($total / 2); $i++) {
    $operations[] = array('_batch_test_callback_1', array($i, $sleep));
  $operations[] = array('_batch_test_callback_2', array(1, $total / 2, $sleep));
  for ($i = round($total / 2) + 1; $i <= $total; $i++) {
    $operations[] = array('_batch_test_callback_1', array($i, $sleep));
  $operations[] = array('_batch_test_callback_2', array(6, $total / 2, $sleep));
  $batch = array(
    'operations' => $operations, 
    'finished' => '_batch_test_finished_3', 
    'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
  return $batch;

What is wrong in your code is how you set $batch['operations'].

The correct code is the following one.

$operations[] = array('test_function1', array($new_node));
$operations[] = array('test_function2', array($new_node));

$batch = array(
  'operations' => $operations, 

  • 1
    Ok I just created two batch_set functions and it seems to work!
    – Brian
    Jan 19, 2013 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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