You are here

Example: Batch API in Examples for Developers 7

Same name and namespace in other branches
  1. 8 batch_example/batch_example.module \batch_example
  2. 6 batch_example/batch_example.module \batch_example
  3. 3.x modules/batch_example/batch_example.module \batch_example

Outlines how a module can use the Batch API.

Batches allow heavy processing to be spread out over several page requests, ensuring that the processing does not get interrupted because of a PHP timeout, while allowing the user to receive feedback on the progress of the ongoing operations. It also can prevent out of memory situations.

The .install file also shows how the Batch API can be used to handle long-running hook_update_N() functions.

Two harmless batches are defined:

  • batch 1: Load the node with the lowest nid 100 times.
  • batch 2: Load all nodes, 20 times and uses a progressive op, loading nodes by groups of 5.

See also

Batch operations

Parent topics

File

batch_example/batch_example.module, line 8
Outlines how a module can use the Batch API.

Functions

Namesort descending Location Description
batch_example_batch_1 batch_example/batch_example.module Batch 1 definition: Load the node with the lowest nid 1000 times.
batch_example_batch_2 batch_example/batch_example.module Batch 2 : Prepare a batch definition that will load all nodes 20 times.
batch_example_finished batch_example/batch_example.module Batch 'finished' callback used by both batch 1 and batch 2.
batch_example_lowest_nid batch_example/batch_example.module Utility function - simply queries and loads the lowest nid.
batch_example_menu batch_example/batch_example.module Implements hook_menu().
batch_example_op_1 batch_example/batch_example.module Batch operation for batch 1: load a node.
batch_example_op_2 batch_example/batch_example.module Batch operation for batch 2 : load all nodes, 5 by five.
batch_example_simple_form batch_example/batch_example.module Form builder function to allow choice of which batch to run.
batch_example_simple_form_submit batch_example/batch_example.module Submit handler.
batch_example_update_7100 batch_example/batch_example.install Example of batch-driven update function.
_batch_example_get_http_requests batch_example/batch_example.module Utility function to count the HTTP requests in a session variable.
_batch_example_update_http_requests batch_example/batch_example.module Utility function to increment HTTP requests in a session variable.

Classes

Namesort descending Location Description
BatchExampleTestCase batch_example/batch_example.test Functional tests for the Batch Example module.