PHP Classes

Thread: A class to implement multi-threaded applications

Recommend this page to a friend!
     
  Info   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 60%Total: 8,732 All time: 185 This week: 68Up
Version License Categories
php_fork 1.0.0The PHP LicenseUnix, Language
Description 

Author

Wrapper around the pcntl_fork() stuff, with a API set like Java language.
Practical usage is done by extending this class, and re-defining the run() method.
This way PHP developers can enclose logic into a class that extends PHP_Fork, then execute the start() method that forks a child process.
Communications with the forked process is ensured by using a Shared Memory Segment; by using a user-defined signal and this shared memory developers can access to child process methods that returns a serializable variable.

The shared variable space can be accessed with the tho methods:
o void setVariable($name, $value)
o mixed getVariable($name)

$name must be a valid PHP variable name;
$value must be a variable or a serializable object.
Resources (db connections, streams, etc.) cannot be serialized and so they're not correctly handled.

Only runs on *NIX systems, because Windows lacks of the needed pcntl ext.

Picture of Luca Mariano
Name: Luca Mariano <contact>
Classes: 1 package by
Country: Italy Italy

Recommendations

Threads PHP
php_fork

  Files folder image Files (8)  
File Role Description
Accessible without login Plain text file action_dispatcher.php Example shows a multiprocess application scheme where all processes run a sleep() cycle, and a centralized dispatcher pass them the work.
Accessible without login Plain text file basic.php Example a basic example, only two pseudo-threads that increment a counter simultaneously
Accessible without login Plain text file exec_methods.php Example shows how to execute methods into the child process.
Plain text file Fork.php Class Main class
Accessible without login Plain text file INSTALL Doc. installation instructions
Accessible without login Plain text file passing_vars.php Example shows variable exchange between the parent process and started pseudo-threads.
Accessible without login HTML file php_fork-api.html Doc. API docs
Accessible without login Plain text file simple_controller.php Example shows how to attach a controller to started pseudo-threads.

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Reuses Unique User Downloads Download Rankings  
 0%2
Total:8,732
This week:0
All time:185
This week:68Up
 User Ratings  
 
 All time
Utility:75%StarStarStarStar
Consistency:80%StarStarStarStarStar
Documentation:75%StarStarStarStar
Examples:78%StarStarStarStar
Tests:-
Videos:-
Overall:60%StarStarStarStar
Rank:1118