PHP Classes

File: data_distribution.php

Recommend this page to a friend!
  Classes of Cuthbert Martin Lwinga   PHP Threading   data_distribution.php   Download  
File: data_distribution.php
Role: Auxiliary script
Content type: text/plain
Description: Configuration script
Class: PHP Threading
Run parallel tasks that share PHP variables
Author: By
Last change:
Date: 15 days ago
Size: 541 bytes
 

Contents

Class file image Download
<?php
include_once("ThreadManager.php");
ThreadManager::warmUp($processes = 2); // will create 2 threads and keep them active
ThreadManager::var("seconds",1); // will create and bind this varible to all threads, when binden in the threads it can be accessed like any variable
for($i = 0;$i < 2; $i++){
   
$closure = function ($seconds) {
   
sleep($seconds);
    if (
true) {
        echo
"hello\n";
    }
};
   
ThreadManager::execute($closure);
}
ThreadManager::wait(); # wait for threads to finish
ThreadManager::shutdown(); # will kill and clean memory
?>