Login   Register  
PHP Classes
elePHPant
Icontem

File: test/class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of AlexanderC  >  Threadator  >  test/class.php  >  Download  
File: test/class.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Threadator
Create threads and send messages between them
Author: By
Last change:
Date: 3 months ago
Size: 698 bytes
 

Contents

Class file image Download
<?php
/**
 * @author AlexanderC <self@alexanderc.me>
 * @date 4/7/14
 * @time 10:30 PM
 */

require "./bootstrap.php";
require 
"./classes/EchoThread.php";

for(
$i 0$i T_MAX$i++) {
    
usleep(400);
    
$thread $factory->create(EchoThread::class);
    
$thread->setStringToEcho(microtime(true));
}

echo 
"Main process #{$runtime->getPid()} running\n";

// start all threads
$runtime->run();

// receive thread messages
$messages = [];
foreach(
$runtime->receiveMessage() as $result => $message) {
    if(
$result) {
        
$messages[] = $message;
    }
}
echo 
"Messages: " implode(", "$messages) . "\n";

// end work
$runtime->join();
exit(
"Main process #{$runtime->getPid()} stopped\n");