Skip to content

Instantly share code, notes, and snippets.

@szepeshazi
Created January 3, 2012 20:37
Show Gist options
  • Save szepeshazi/1556812 to your computer and use it in GitHub Desktop.
Save szepeshazi/1556812 to your computer and use it in GitHub Desktop.
Test script to show how Elgg 1.8+ handles asynchronous parallel metadata updates.
<?php
require_once (dirname(__FILE__)) . '/engine/start.php';
$options = array(
'type' => 'object',
'subtype' => 'paraleltest',
'limit' => 1
);
$access = elgg_set_ignore_access(true);
$entities = elgg_get_entities($options);
if (is_array($entities) && !empty($entities)) {
$entity = $entities[0];
if (isset($entity->impressions)) {
$entity->impressions = $entity->impressions + 1;
} else {
$entity->impressions = 1;
}
error_log("Counter is now {$entity->impressions}");
} else {
// Pick any user to be the owner of the object
$users = elgg_get_entities(array('type' => 'user'));
$user = $users[0];
$object = new ElggObject();
$object->subtype = 'paraleltest';
$object->owner_guid = $user->guid;
$object->container_guid = $user->guid;
$object->access_id = ACCESS_PUBLIC;
$object->save();
$object->impressions = 0;
$object->save();
error_log("Test object created");
}
elgg_set_ignore_access($access);
?>
@szepeshazi
Copy link
Author

  1. Drop this script into your Elgg installation's root directory.
  2. Hit http://your-elgg-site/parallel_test.php in your browser a couple of times, and watch the log. Counter should increase one by one.
  3. Run "ab -n 100 -c 10 http://your-elgg-site/parallel_test.php" and watch the log. You'll see at some point the integer property turning into an array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment