Example: Batch API in Examples for Developers 8
Same name and namespace in other branches
- 6 batch_example/batch_example.module \batch_example
- 7 batch_example/batch_example.module \batch_example
- 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 reduce 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
Parent topics
File
- batch_example/
batch_example.module, line 8 - Outlines how a module can use the Batch API.
Functions
Name | Location | Description |
---|---|---|
batch_example_finished |
batch_example/ |
Batch 'finished' callback used by both batch 1 and batch 2. |
batch_example_op_1 |
batch_example/ |
Batch operation for batch 1: one at a time. |
batch_example_op_2 |
batch_example/ |
Batch operation for batch 2: five at a time. |
batch_example_update_8001 |
batch_example/ |
Example of batch-driven update function. |
Classes
Name | Location | Description |
---|---|---|
BatchExampleWebTest |
batch_example/ |
Functional tests for the Batch Example module. |