PHP Classes

File: test.php

Recommend this page to a friend!
  Packages of Alex Lau   Multi-thread Simulation   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: An example
Class: Multi-thread Simulation
Emulate threads using separate HTTP requests
Author: By
Last change: a better testcase
Date: 17 years ago
Size: 858 bytes
 

 

Contents

Class file image Download
<?php

include_once("Thread.php");

function test($test_arg){

    return "Pass in variable ".$test_arg.".<br />";

}

function test_2($test_arg){

    $start = time();

    while (time() < $start+$test_arg){

        

    }

    return $test_arg." seconds have passed.<br />";

}



$program_start_time = time();



$thread_a = new Thread("localhost",80);

$thread_a->setFunc("test",array("Hello World"));

$thread_a->start();



$thread_b = new Thread("localhost",80);

$thread_b->setFunc("test_2",array(2));

$thread_b->start();



$thread_c = new Thread("localhost",80);

$thread_c->setFunc("test_2",array(1));

$thread_c->start();



echo $thread_a->getreturn();

echo $thread_b->getreturn();

echo $thread_c->getreturn();



echo "Main Program has run ".(time()-$program_start_time)." seconds<br />";



?>