PHP Classes

File: examples/example.namedThreads.php

Recommend this page to a friend!
  Classes of Don Bauer   Power Process   examples/example.namedThreads.php   Download  
File: examples/example.namedThreads.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Power Process
Create processes to PHP code in parallel
Author: By
Last change:
Date: 11 years ago
Size: 905 bytes


Class file image Download

// 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(

// 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;
    } else {
// No more data so let's 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++) {