PHP Classes

File: ThreadedTaskDemo.php

Recommend this page to a friend!
  Classes of Cuthbert Martin Lwinga   PHP Multithreading with Shared Memory   ThreadedTaskDemo.php   Download  
File: ThreadedTaskDemo.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: 908 bytes
 

Contents

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


echo
"? Successfully completed a 2-hour (7200-second) sleep simulation in just 15 seconds! ?\n\n";
echo
"? This serves as a stress test to showcase the robustness and efficiency of memory allocation in our multithreading environment. ?\n\n";
echo
"? Note: This test uses 800 threads. While this demonstrates the system's impressive capacity, the practicality of using this many threads is open for discussion.
\n? Feel free to adjust the thread count to a more suitable number for your specific use case. ?\n"
;


function
testbackground($param=1){
   
sleep(1);
   
    if (
$param%1000 == 0){
        echo
"\n $param EXECTUED\n";
    }
}

for (
$i=0; $i < 7200; $i++) {
   
Threads::addTask("testbackground",[$i]);
}

Threads::run($Threads=800);

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

?>