Power Process: Create processes to PHP code in parallel

Recommend this page to a friend!
  Info   View files (18)   Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 299 All time: 7,307 This week: 354
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: 34
All time rank: 2729348 in United States United States
Week rank: 243 20 in United States United States

Details
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  
File Role Description
docs (7 files, 3 directories)
examples (3 files)
LICENSE Lic. License text
PowerProcess.class.php Class Class source
README Doc. Documentation

  Files  /  docs  
File Role Description
media (2 files)
PowerProcess (2 files)
__filesource (1 file)
   blank.html Doc. Documentation
   classtrees_PowerProcess.html Doc. Documentation
   elementindex.html Doc. Documentation
   elementindex_PowerProcess.html Doc. Documentation
   index.html Doc. Documentation
   li_PowerProcess.html Doc. Documentation
   packages.html Doc. Documentation

  Files  /  docs  /  media  
File Role Description
   banner.css Data Auxiliary data
   stylesheet.css Data Auxiliary data

  Files  /  docs  /  PowerProcess  
File Role Description
   PowerProcess.html Doc. Documentation
   _PowerProcess.class.php.html Doc. Documentation

  Files  /  docs  /  __filesource  
File Role Description
   fsource_PowerProce...cess.class.php.html Doc. Documentation

  Files  /  examples  
File Role Description
   example.deamon.php Example Example script
   example.namedThreads.php Example Example script
   example.normal.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:299
This week:0
All time:7,307
This week:354
User Comments (2)
 

For more information send a message to info at phpclasses dot org.