Public Member Functions | Data Fields | Protected Member Functions

ZendX_Console_Process_Unix Class Reference

Public Member Functions

 __construct ($puid=null, $guid=null, $umask=null)
 __destruct ()
 start ()
 stop ()
 isRunning ()
 setVariable ($name, $value)
 getVariable ($name)
 getLastAlive ()
 getPid ()

Data Fields

const VOID_METHOD = 'void_method'
const RETURN_METHOD = 'void_method'

Protected Member Functions

 _setAlive ()
 _callCallbackMethod ($methodName, array $argList=array(), $type=self::VOID_METHOD)
 _run ()

Detailed Description

Definition at line 31 of file Unix.php.


Constructor & Destructor Documentation

__construct ( puid = null,
guid = null,
umask = null 
)

Constructor method

Allocates a new pseudo-thread object. Optionally, set a PUID, a GUID and a UMASK for the child process. This also initialize Shared Memory Segments for process communications.

Parameters:
integer$puid
integer$guid
integer$umask
Exceptions:
ZendX_Console_Process_ExceptionWhen running on windows
ZendX_Console_Process_ExceptionWhen running in web enviroment
ZendX_Console_Process_ExceptionWhen shmop_* functions don't exist
ZendX_Console_Process_ExceptionWhen pcntl_* functions don't exist
ZendX_Console_Process_ExceptionWhen posix_* functions don't exist

Definition at line 144 of file Unix.php.

__destruct (  )

Stop the child on destruction

Definition at line 186 of file Unix.php.


Member Function Documentation

_callCallbackMethod ( methodName,
array $  argList = array(),
type = self::VOID_METHOD 
) [protected]

This is called from within the parent; all the communication stuff is done here.

Parameters:
string$methodName
array$argList
string$type
Returns:
mixed

Definition at line 385 of file Unix.php.

_run (  ) [abstract, protected]

This method actually implements the pseudo-thread logic.

Returns:
void
_setAlive (  ) [protected]

Set a pseudo-thread property that can be read from parent process in order to know the child activity.

Practical usage requires that child process calls this method at regular time intervals; parent will use the getLastAlive() method to know the elapsed time since the last pseudo-thread life signals...

Returns:
void

Definition at line 370 of file Unix.php.

getLastAlive (  )

Read the time elapsed since the last child setAlive() call.

This method is useful because often we have a pseudo-thread pool and we need to know each pseudo-thread status. If the child executes the setAlive() method, the parent with getLastAlive() can know that child is alive.

Returns:
integer

Definition at line 343 of file Unix.php.

getPid (  )

Returns the PID of the current pseudo-thread.

Returns:
integer

Definition at line 355 of file Unix.php.

getVariable ( name )

Get a variable from the shared memory segment. Returns NULL if the variable doesn't exist.

Parameters:
string$name
Returns:
mixed

Definition at line 322 of file Unix.php.

isRunning (  )

Test if the pseudo-thread is already started.

Returns:
boolean

Definition at line 290 of file Unix.php.

setVariable ( name,
value 
)

Set a variable into the shared memory segment, so that it can accessed both from the parent and from the child process. Variable names beginning with underlines are only permitted to interal functions.

Parameters:
string$name
mixed$value
Exceptions:
ZendX_Console_Process_ExceptionWhen an invalid variable name is supplied
Returns:
void

Definition at line 305 of file Unix.php.

start (  )

Causes this pseudo-thread to begin parallel execution.

This method first checks of all the Shared Memory Segment. If okay, it forks the child process, attaches signal handler and returns immediatly. The status is set to running, and a PID is assigned. The result is that two pseudo-threads are running concurrently: the current thread (which returns from the call to the start() method) and the other thread (which executes its run() method).

Exceptions:
ZendX_Console_Process_ExceptionWhen SHM segments can't be created
ZendX_Console_Process_ExceptionWhen process forking fails
Returns:
void

Definition at line 207 of file Unix.php.

stop (  )

Causes the current thread to die.

The relative process is killed and disappears immediately from the processes list.

Returns:
boolean

Definition at line 269 of file Unix.php.


Field Documentation

const RETURN_METHOD = 'void_method'

Return method

Definition at line 41 of file Unix.php.

const VOID_METHOD = 'void_method'

Void method

Definition at line 36 of file Unix.php.


The documentation for this class was generated from the following file: