function _views_bulk_operations_execute_next in Views Bulk Operations (VBO) 6
Gets the next item in the loop taking into consideration server limits for high performance batching.
Return value
- The next object in the objects array.
1 call to _views_bulk_operations_execute_next()
- _views_bulk_operations_execute_multiple in ./
views_bulk_operations.module - Helper function for multiple execution operations.
File
- ./
views_bulk_operations.module, line 1633 - Allows operations to be performed on items selected in a view.
Code
function _views_bulk_operations_execute_next($index, $objects, $batch) {
static $loop = 0, $last_mem = -1, $last_time = 0, $memory_limit = 0, $time_limit = 0;
// Early return if we're done.
if ($index >= count($objects)) {
return FALSE;
}
// Get the array keys.
$keys = array_keys($objects);
if ($batch) {
// Keep track of how many loops we have taken.
$loop++;
// Memory limit in bytes.
$memory_limit = $memory_limit ? $memory_limit : (int) preg_replace('/[^\\d\\s]/', '', ini_get('memory_limit')) * 1048576;
// Max time execution limit.
$time_limit = $time_limit ? $time_limit : (int) ini_get('max_execution_time');
// Current execution time in seconds.
$current_time = time() - $_SERVER['REQUEST_TIME'];
$time_left = $time_limit - $current_time;
if ($loop == 1) {
$last_time = $current_time;
// Never break the first loop.
return $objects[$keys[$index]];
}
// Break when current free memory past threshold. Default to 32 MB.
if ($memory_limit - memory_get_usage() < variable_get('batch_free_memory_threshold', 33554432)) {
return FALSE;
}
// Break when peak free memory past threshold. Default to 8 MB.
if ($memory_limit - memory_get_peak_usage() < variable_get('batch_peak_free_memory_threshold', 8388608)) {
return $objects[$keys[$index]];
}
// Break when execution time remaining past threshold. Default to 15 sec.
if ($time_limit - $current_time < variable_get('batch_time_remaining_threshold', 15)) {
return FALSE;
}
$last_time = $current_time;
return $objects[$keys[$index]];
}
else {
return $objects[$keys[$index]];
}
}