PHP Classes
elePHPant
Icontem

Power Process: Create processes to PHP code in parallel

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2012-01-11 (3 years ago) RSS 2.0 feedNot enough user ratingsTotal: 281 This week: 2All time: 6,914 This week: 578Up
Version License PHP version Categories  
power-process 2.0MIT/X Consortium ...5.3PHP 5, Unix, Language
Description Author  

This class can create processes to PHP code in parallel.

It can fork new processes with pcntl extension and return the information on whether the current script is running the parent or the just created child process.

The forked processes can be made to run as standalone daemons.

The class can send POSIX signals to the child processes eventually to make them exit. Callback functions may be registered to handle those signals.

The class can also execute separate programs in the context of the current process.

Picture of Don Bauer
Name: Don Bauer <contact>
Classes: 3 packages by
Country: United States United States
Age: 29
All time rank: 2651335 in United States United States
Week rank: 409 Up37 in United States United States Up

Details provided by the author  
ABOUT
	PowerProcess is a PCNTL and POSIX wrapper for *nix systems running PHP
	
	It is for managing and running forked process for parrallel computing with PHP

FEATURES
	* Easy Process Threading for Parallel Computing
	* Named Thread Support
	* Linux/Unix Signal Handling
	* Daemonizing PHP Scripts
	* Automatic Ticks (No longer have to add calls to Tick() in loops)
	* Dynamic callback support for *nix signals and custom events
	* Process Space Takeover Ability

VERSION HISTORY
	2.0 - 2011-12-29
		Added Restart()
		Added Daemonize()
		Changed a number of method names
		Added Log()
		Added config options to constructor
		Added Linux/Unix signal handlers for SIGHUP and SIGTERM 
	1.1 - 2011-11-12
		Added named thread support
		Added ThreadStatus check support
	1.0 - 2011-11-01
		Forked from PowerSpawn 1.0

IMPORTANT NOTE
	PowerProcess is very similar to PowerSpawn, however, more features are available in 
	PowerProcess and it is not backwards compatible.  Changes to convert code to PowerProcess
	are minimal and should be easy enough for you if you have experience with PowerSpawn

ANOTHER IMPORTANT NOTE
	Open database connections made in the control process do not carry over to the threads.
	This means if you are doing work with a MySQL (or other) database, you will need to open a 
	new database connection in the thread code.

HOW TO USE
	To use PowerProcess, once included you just need to simply instance the class like so:
	
	$pp = new PowerProcess();
	
	This will enable threading and daemon capabilities for your code.  Now that you have instanced
	the class, you will need to set up your control loop like so:
	
	while ( $pp->RunControlCode() ) {
		if ( __SOME_CONDITION_THAT_DETERMINES_IF_YOU_HAVE_DATA_TO_PROCESS__ ) {
			$pp->threadData = __YOUR_DATA__;
			$pp->SpawnThread();
		} else {
			$pp->Shutdown();
		}
	}
	
	That is what a basic control loop will look like.  When a new thread is spawned, it will resume
	execution from the SpawnThread() method call.  It will break out of the while loop and execute
	any code below the end of the while loop as a separate process than the one you started.
	
	When the Shutdown() method is called, the Control Loop will wait for all running threads to exit and
	it too will break out of the while loop and resume executing the rest of the script.
	
	If you don't want to control process to execute the code below the loop, you have two options to prevent
	it from doing do.
	
	First, you should call shutdown with an extra parameter: $pp->Shutdown(true)
	This will make shutdown call exit() after all threads have completed.
	
	Second, you can wrap all the code you don't want the exiting control process to execute inside of
	and if{} statement like so:
	
	if ($pp->RunThreadCode()) {
		// My Code Here
	}
	
MAKING A DAEMON
	You don't have to use PowerProcess for threading.  You can also use it to create a PHP deamon.  You simply
	instance the PowerProcess object by setting the daemon parameter to true.
	
	$pp = new PowerProcess(1,0,true); // 1 Thread, No Timeout, Daemon set to true
	
Please check the examples included for more information on how to use PowerProcess
  Files folder image Files  
File Role Description
Files folder imagedocs (7 files, 3 directories)
Files folder imageexamples (3 files)
Accessible without login Plain text file LICENSE Lic. License text
Plain text file PowerProcess.class.php Class Class source
Accessible without login Plain text file README Doc. Documentation

  Files folder image Files  /  docs  
File Role Description
Files folder imagemedia (2 files)
Files folder imagePowerProcess (2 files)
Files folder image__filesource (1 file)
  Accessible without login HTML file blank.html Doc. Documentation
  Accessible without login HTML file classtrees_PowerProcess.html Doc. Documentation
  Accessible without login HTML file elementindex.html Doc. Documentation
  Accessible without login HTML file elementindex_PowerProcess.html Doc. Documentation
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login HTML file li_PowerProcess.html Doc. Documentation
  Accessible without login HTML file packages.html Doc. Documentation

  Files folder image Files  /  docs  /  media  
File Role Description
  Accessible without login Plain text file banner.css Data Auxiliary data
  Accessible without login Plain text file stylesheet.css Data Auxiliary data

  Files folder image Files  /  docs  /  PowerProcess  
File Role Description
  Accessible without login HTML file PowerProcess.html Doc. Documentation
  Accessible without login HTML file _PowerProcess.class.php.html Doc. Documentation

  Files folder image Files  /  docs  /  __filesource  
File Role Description
  Accessible without login HTML file fsource_PowerProce...cess.class.php.html Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example.deamon.php Example Example script
  Accessible without login Plain text file example.namedThreads.php Example Example script
  Accessible without login Plain text file example.normal.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%Total:281All time:6,914
 This week:2This week:578Up
 User Comments (2)