API Documentation

ZendX/Console/Process/Unix.php

Classes |

Properties

Description

Zend Framework

LICENSE

This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.


Classes

ZendX_Console_Process_Unix

Properties

 
 
ZendX  
Yes 
No 

Description

ZendX_Console_Process_Unix allows you to spawn a class as a separated process

Methods

__construct, __destruct, _callCallbackMethod, _cleanProcessContext, _createIpcSegment, _createIpcSemaphore, _readFromIpcSegment, _run, _sendSigUsr1, _setAlive, _sigHandler, _waitForIpcSemaphore, _writeToIpcSegment, _writeVariable, getLastAlive, getPid, getVariable, isRunning, setVariable, start, stop,

__construct( integer   $puid = null, integer   $guid = null, integer   $umask = null, ) : n/a

Description

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.


Arguments

Name Type Description Default
$puid integer | null
$guid integer | null
$umask integer | null

Return value

Type Description
n/a n/a

Tags

Name Description
throws ZendX_Console_Process_Exception
When running on windows
throws ZendX_Console_Process_Exception
When running in web enviroment
throws ZendX_Console_Process_Exception
When shmop_* functions don't exist
throws ZendX_Console_Process_Exception
When pcntl_* functions don't exist
throws ZendX_Console_Process_Exception
When posix_* functions don't exist

__destruct( ) : n/a

Description

Stop the child on destruction

Return value

Type Description
n/a n/a

_callCallbackMethod( string   $methodName, array   $argList = array, string   $type = self, ) : mixed

Description

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

Arguments

Name Type Description Default
$methodName string |
$argList array | array
$type string | self

Return value

Type Description
mixed

_cleanProcessContext( ) : void

Description

Destroy thread context and free relative resources.

Return value

Type Description
void

_createIpcSegment( ) : boolean

Description

Create an IPC segment

Return value

Type Description
boolean

Tags

Name Description
throws ZendX_Console_Process_Exception
When SHM segment can't be created

_createIpcSemaphore( ) : boolean

Description

Create IPC semaphore

Return value

Type Description
boolean

Tags

Name Description
throws ZendX_Console_Process_Exception
When semaphore can't be created

_readFromIpcSegment( ) : void

Description

Read data from IPC segment

Return value

Type Description
void

Tags

Name Description
throws ZendX_Console_Process_Exception
When writing of SHM segment fails

_run( ) : void

Description

This method actually implements the pseudo-thread logic.

Return value

Type Description
void

_sendSigUsr1( ) : void

Description

Sends signal to the child process

Return value

Type Description
void

_setAlive( ) : void

Description

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...


Return value

Type Description
void

_sigHandler( integer   $signo, ) : void

Description

This is the signal handler that makes the communications between client and server possible.

Arguments

Name Type Description Default
$signo integer |

Return value

Type Description
void

_waitForIpcSemaphore( ) : void

Description

Wait for IPC Semaphore

Return value

Type Description
void

_writeToIpcSegment( ) : void

Description

Write data to IPC segment

Return value

Type Description
void

Tags

Name Description
throws ZendX_Console_Process_Exception
When writing of SHM segment fails

_writeVariable( string   $name, mixed   $value, ) : void

Description

Acutally Write a variable to the shared memory segment

Arguments

Name Type Description Default
$name string |
$value mixed |

Return value

Type Description
void

getLastAlive( ) : integer

Description

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.


Return value

Type Description
integer

getPid( ) : integer

Description

Returns the PID of the current pseudo-thread.

Return value

Type Description
integer

getVariable( string   $name, ) : mixed

Description

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

Arguments

Name Type Description Default
$name string |

Return value

Type Description
mixed

isRunning( ) : boolean

Description

Test if the pseudo-thread is already started.

Return value

Type Description
boolean

setVariable( string   $name, mixed   $value, ) : void

Description

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.

Arguments

Name Type Description Default
$name string |
$value mixed |

Return value

Type Description
void

Tags

Name Description
throws ZendX_Console_Process_Exception
When an invalid variable name is supplied

start( ) : void

Description

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).


Return value

Type Description
void

Tags

Name Description
throws ZendX_Console_Process_Exception
When SHM segments can't be created
throws ZendX_Console_Process_Exception
When process forking fails

stop( ) : boolean

Description

Causes the current thread to die.

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


Return value

Type Description
boolean

Properties

$_guid, $_internalIpcData, $_internalIpcKey, $_internalSemKey, $_ipcIsOkay, $_ipcSegFile, $_ipcSemFile, $_isChild, $_isRunning, $_name, $_pid, $_puid,

  private  $_guid = null

GUID of the child process ownerinteger


  private  $_internalIpcData = array

A data structure to hold data for Inter Process Communicationsarray


  private  $_internalIpcKey =

Key to access to Shared Memory Area.integer


  private  $_internalSemKey =

Key to access to Sync Semaphore.integer


  private  $_ipcIsOkay =

Is Shared Memory Area OK? If not, the start() method will block.boolean
<p>Otherwise we'll have a running child without any communication channel.</p>

  private  $_ipcSegFile =

Filename of the IPC segment filestring


  private  $_ipcSemFile =

Filename of the semaphor filestring


  private  $_isChild = false

Wether we are into child process or notboolean


  private  $_isRunning = false

Whether the process is yet forked or notboolean


  private  $_name =

Unique thread namestring


  private  $_pid = null

PID of the child processinteger


  private  $_puid = null

UID of the child process ownerinteger


Constants

  RETURN_METHOD = void_method

Return method


  VOID_METHOD = void_method

Void method


Documentation was generated by DocBlox.