PHP--Fork
[ class tree: PHP--Fork ] [ index: PHP--Fork ] [ all elements ]

Class: executeThread

Source Location: /PHP_Fork-0.3.2/examples/simple_controller.php

Class Overview

PHP_Fork
   |
   --executeThread

PHP_Fork class. Wrapper around the pcntl_fork() stuff with a API set like Java language.


Author(s):

Version:

  • 1.0

Variables

Methods


Inherited Variables

Inherited Methods

Class: PHP_Fork

PHP_Fork::PHP_Fork()
PHP_Fork::PHP_Fork() Allocates a new pseudo-thread object and set its name to $name.
PHP_Fork::getLastAlive()
PHP_Fork::getLastAlive()
PHP_Fork::getName()
PHP_Fork::getName() Returns this pseudo-thread's name.
PHP_Fork::getPid()
PHP_Fork::getPid() Return the PID of the current pseudo-thread.
PHP_Fork::getVariable()
PHP_Fork::getVariable()
PHP_Fork::isActive()
PHP_Fork::isActive()
PHP_Fork::isRunning()
PHP_Fork::isRunning() Test if the pseudo-thread is already started.
PHP_Fork::register_callback_func()
PHP_Fork::register_callback_func()
PHP_Fork::run()
PHP_Fork::run()
PHP_Fork::setAlive()
PHP_Fork::setAlive()
PHP_Fork::setName()
PHP_Fork::setName() Changes the name of this thread to the given name.
PHP_Fork::setVariable()
PHP_Fork::setVariable()
PHP_Fork::start()
PHP_Fork::start() Causes this pseudo-thread to begin parallel execution.
PHP_Fork::stop()
PHP_Fork::stop() Causes the current thread to die.

Class Details

[line 40]
PHP_Fork class. 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. Example:

  1.   class executeThread extends PHP_Fork {
  2.      var $counter;
  3.  
  4.      function executeThread($name)
  5.      {
  6.          $this->PHP_Fork($name);
  7.          $this->counter = 0;
  8.      }
  9.  
  10.      function run()
  11.      {
  12.          $i = 0;
  13.          while ($i < 10{
  14.              print time("-(" $this->getName(")-" $this->counter++ . "\n";
  15.              sleep(1);
  16.              $i++;
  17.          }
  18.      }
  19.  }

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:

  • void setVariable($name, $value)
  • 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.

Requires PHP build with --enable-cli --with-pcntl --enable-shmop.
Only runs on *NIX systems, because Windows lacks of the pcntl ext.



[ Top ]


Class Variables

$counter =

[line 41]


Type:   mixed


[ Top ]



Method Detail

executeThread (Constructor)   [line 43]

executeThread executeThread( $name)


Parameters:

   $name   — 

[ Top ]

getCounter   [line 71]

void getCounter( )


[ Top ]

run   [line 49]

void run( )


Overrides PHP_Fork::run() (PHP_Fork::run())
[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:41:28 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.