PHP Classes


Recommend this page to a friend!
  Classes of Don Bauer  >  Power Process  >  README  >  Download  
Role: Documentation
Content type: text/plain
Description: Documentation
Class: Power Process
Create processes to PHP code in parallel
Author: By
Last change: Added basic howto
Date: 10 years ago
Size: 3,142 bytes


Class file image Download
	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

	* 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

	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

	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

	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.

	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() ) {
			$pp->threadData = __YOUR_DATA__;
		} else {
	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
	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
For more information send a message to info at phpclasses dot org.