PHP Classes

File: Example_Usage.php

Recommend this page to a friend!
  Classes of Cuthbert Martin Lwinga   PHP Multithreading with Shared Memory   Example_Usage.php   Download  
File: Example_Usage.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Multithreading with Shared Memory
Run multiple functions at the same time
Author: By
Last change:
Date: 4 months ago
Size: 723 bytes
 

Contents

Class file image Download
<?php
include_once("SharedMemoryHandler.php");
include_once(
"Threads.php");
use
NameSpaceThreads\Threads;

function
testbackground($param=1){
   
mt_srand(); // Seed the random number generator
   
$randomNumber = mt_rand(0, 4);
    echo
"\n $param will sleep for $randomNumber s\n";
   
sleep($randomNumber);
    echo
"\n $param woke up\n";
}

Threads::addTask("testbackground",[1]);
Threads::addTask("testbackground",[2]);
Threads::addTask("testbackground",[3]);
Threads::addTask("testbackground",[4]);
Threads::addTask("testbackground",[5]);
Threads::addTask("testbackground",[6]);
Threads::addTask("testbackground",[7]);
Threads::addTask("testbackground",[8]);
Threads::run($Threads=10);

echo
"\n\n all done \n\n";

?>