<?php

require "config.php";
require_once WWW_DIR . "/lib/groups.php";
require_once WWW_DIR . "/lib/binaries.php";
require_once WWW_DIR . '/lib/powerprocess.php';
$groups = new Groups();
$groupList = $groups->getActive();
unset($groups);
$ps = new PowerProcess();
$ps->RegisterCallback('psUpdateComplete');
$ps->maxThreads = 10;
$ps->tickCount = 10000;
// value in usecs. change this to 1000000 (one second) to reduce cpu use
$ps->threadTimeLimit = 0;
// Disable child timeout
echo "Starting threaded backfill process\n";
while ($ps->RunControlCode()) {
    // Start the parent loop
    if (count($groupList)) {
        // We still have groups to process
        if ($ps->SpawnReady()) {
            // Spawn another thread
            $ps->threadData = array_pop($groupList);
            echo "[Thread-MASTER] Spawning new thread.  Still have " . count($groupList) . " group(s) to update after this\n";
            $ps->spawnThread();
        } else {
            // There are no more slots available to run
            //$ps->tick();
            //echo ".\n";
        }
<?php

// Include PowerProcess
require_once '../PowerProcess.class.php';
// Instance new PowerProcess class
$pp = new PowerProcess(2, 30, false, 'php://stdout', true);
// Make some fake data (We'll use this for names)
$data = array('updater', 'patcher', 'watchdog');
// Start the Control Loop
while ($pp->RunControlCode()) {
    // Check if we still have data in our stack
    if (count($data)) {
        // Check to see if we can spawn a thread
        if ($pp->SpawnReady()) {
            // Assign thread data and spawn
            $pp->threadData = 10;
            $pp->SpawnThread(array_shift($data));
        }
    } else {
        // No more data so let's shutdown
        $pp->Shutdown();
    }
}
// Start the thread code
if ($pp->RunThreadCode()) {
    // Announce who we are
    $pp->Log("Hello! I am '" . $pp->WhoAmI() . "' and I am going to pretend to do some work now");
    // Sleep for 10 seconds
    for ($i = 0; $i < $pp->threadData; $i++) {
        sleep(1);
    }
Пример #3
0
<?php

// Include PowerProcess
require_once '../PowerProcess.class.php';
// Instance new PowerProcess class with 2 threads, 30 second timeout,
// as daemon with logging to daemonlog.txt
$pp = new PowerProcess(2, 30, true, 'daemonlog.txt', false);
// Write some stuff to the log file
$pp->Log("Greetings! I am a Daemon example!");
$pp->Log("My PID is " . $pp->GetPID());
$pp->Log("I am going to write some stuff to a file now.");
// Echo this so the user can see that the daemon is starting
// The echo lines will go to STOUT instead of the log file
echo "Daemon started with 2 threads...\n";
echo "You can run `tail -f daemonlog.txt` to follow my progress...\n";
// Generate some fake data
$data = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
// Start the control loop
while ($pp->RunControlCode()) {
    // Check for data in the queue
    if (count($data)) {
        // Check if we can spawn
        if ($pp->SpawnReady()) {
            // Spawn a new thread
            $pp->SpawnThread('Thread-' . array_shift($data));
        }
    } else {
        // No more data - shutdown
        $pp->Shutdown();
        $pp->Log("The daemon is now exiting...");
    }
Пример #4
0
<?php

// Include PowerProcess
require_once '../PowerProcess.class.php';
// Instance new PowerProcess class with 2 threads, 10 second timeout,
// standalone, log to STDOUT and include debug logging
// Since we have a 10 second timeout, the last five threads will be
// terminated by PowerProcess
$pp = new PowerProcess(2, 10, false, 'php://stdout', true);
// Make some fake data
$data = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
// Start the control loop
while ($pp->RunControlCode()) {
    // Check if we have data to process
    if (count($data) > 0) {
        // We have data to process
        if ($pp->SpawnReady()) {
            // Assign the thread data
            $pp->threadData = array_shift($data);
            // Try to spawn the thread
            if (!$pp->SpawnThread()) {
                $pp->Log("Error spawning thread");
                // Sleep just in case
                sleep(1);
                // Add the data back to the queue
                $data[] = $pp->threadData;
            }
        }
    } else {
        // No more data to process - shutdown
        $pp->Shutdown(true);