Skip to content

Instantly share code, notes, and snippets.

@beck24
Created November 29, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beck24/d2eefe71f78ac7ae5efb to your computer and use it in GitHub Desktop.
Save beck24/d2eefe71f78ac7ae5efb to your computer and use it in GitHub Desktop.
ElggBatch performance test
<?php
require_once __DIR__ . '/engine/start.php';
echo 'tail your log file';
// Ignore user aborts and allow the script to run forever
ignore_user_abort(true);
session_write_close();
set_time_limit(0);
// Tell the browser that we are done
header("Connection: close");
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();
flush();
elgg_set_ignore_access();
$options = array(
'type' => 'group',
'subtype' => ELGG_ENTITIES_ANY_VALUE,
'limit' => false
);
$batch_size = 100;
$batch = new ElggBatch('elgg_get_entities', $options, null, $batch_size);
error_log('starting batch');
$fetch_time_start = time();
$count = 0;
$b = 0;
foreach ($batch as $e) {
$count++;
if (($count % $batch_size) == 1) {
$b++;
$fetch_time = time() - $fetch_time_start;
error_log('batch #' . $b . ' fetched in ' . $fetch_time . ' seconds');
error_log('start of new batch');
}
if (!($count % $batch_size)) {
error_log('end of batch');
$fetch_time_start = time();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment