How to simulate an admin user in a multi-threaded cron job

I have a process that needs to run repeatedly at an interval (let's say every minute), and also needs to be scaled as far as how many processes are running concurrently, depending on how much "work" there is to do.

The process needs to have access to various Elgg entities and metadata with "admin" privileges.

Initially I setup an admin user and at the beginning of the function I added code to log in as the user, therefore giving the cron job all the Elgg access it needed during the session.


if ($user = authenticate($elgg_username,$elgg_password)) {

login($user, true); 

admin_init(); // Required so that access is properly initialized


However, Elgg will only allow one login per user at a time, so if the 1st cron job was still running when the 2nd one started, the 1st one would automatically be logged out.

So I took a look at \engine\lib\access.php to see how I could "fool" Elgg into thinking I had admin privileges without having to log in as a specific user.

Turns out it's super easy :)


global $is_admin;               

$is_admin = true; 

Done and done.  Just thought I'd share this with y'all in case you had the same requirement.