PHP Classes

Multi-threading in PHP: Run emulated parallel threads with HTTP requests

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (3)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 2,548 This week: 1All time: 1,509 This week: 571Up
Version License PHP version Categories
multi-threading-php 1.0Free for non-comm...5PHP 5, Language
Description 

Author

This class can run emulated parallel threads with HTTP requests to the same server.

It can create parallel threads to run given PHP code by sending HTTP requests to an URL of the same server handled by a script that will execute a given function with optional arguments also passed in the HTTP request.

The class can also handle the HTTP requests to the emulated threads.

On the calling side, the class can check if the emulated thread has finished and retrieves the result as the HTTP response.

Picture of Bijaya Kumar  Behera
Name: Bijaya Kumar Behera <contact>
Classes: 6 packages by
Country: India India
Age: ???
All time rank: 56135 in India India
Week rank: 420 Up26 in India India Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Recommendations

What is the best PHP multithreading class?
How to implement threads in PHP

Need to run multithreaded scripts in PHP
Multithreaded scripts on Windows

Example

<?php
/**
 * Multi Threading
 * @author Bijaya Kumar
 * @email it.bijaya@gmail.com
 * @mobile +91 9911033016
 * @link http://www.digitalwebsolutions.in
**/

    // require class
   
require_once('./thread.class.php');
   
   
// global function
   
include('functions/functions.php');
   
   
// listen
   
mThread::listen();
   
   
   
// start time
   
$time = time () ;
                   
   
//
   
$doSleep_response = NULL;
   
$response2 = NULL;
                       
   
// start thread #1, with receive return value with param value 10
   
mThread::start( array( 'doSleep', &$doSleep_response), 10 ,'bijaya' ) ;
   
   
//start thread #2, without receive return value with param value 10
   
mThread::start( 'doSleep1', 10 , 'kulvir' ) ;
   
   
// start thread #3, without receive return value with param value 10
   
mThread::start( 'doSleep2', 10 , 'ajit' ) ;
       
   
// running till completed
   
while ( mThread::runing () ) ;
        
   
        
    echo
"----------------------<br />" ;
    echo
"Response Return from doSleep <br />" ;
   
var_dump($doSleep_response);
    echo
"<br />----------------------<br />" ;
            
    echo
"====================<br /> Tooks " . (time () - $time ) . ' Secs. 3 threads,<br />====================' ;
   
    die;
?>


  Files folder image Files  
File Role Description
Files folder imagefunctions (1 file)
Accessible without login Plain text file example.php Example example file
Plain text file thread.class.php Class multi thread class

  Files folder image Files  /  functions  
File Role Description
  Accessible without login Plain text file functions.php Aux. user function

 Version Control Unique User Downloads Download Rankings  
 0%
Total:2,548
This week:1
All time:1,509
This week:571Up
User Ratings User Comments (2)
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:-
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1422
 
its really good script for multi threading .
7 years ago (Abdul Hadi Qureshi)
70%StarStarStarStar
works great.
11 years ago (sarthaksahni)
70%StarStarStarStar