PHP Classes

File: test/class.php

Recommend this page to a friend!
  Packages 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: Update of test/class.php
Date: 5 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");