API Documentation

Console/Process/Unix.php

Classes 
category
ZendX
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
ZendX_Console
version
$Id: Unix.php 20165 2010-01-09 18:57:56Z bkarwin $
Classes
ZendX_Console_Process_Unix

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.

\ZendX_Console_Process_Unix

category
ZendX
copyright
Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
license
http://framework.zend.com/license/new-bsd New BSD License
package
ZendX_Console
Constants
RETURN_METHOD
VOID_METHOD
Properties
$_guid
$_internalIpcData
$_internalIpcKey
$_internalSemKey
$_ipcIsOkay
$_ipcSegFile
$_ipcSemFile
$_isChild
$_isRunning
$_name
$_pid
$_puid
Methods
__construct
__destruct
_callCallbackMethod
_cleanProcessContext
_createIpcSegment
_createIpcSemaphore
_readFromIpcSegment
_run
_sendSigUsr1
_setAlive
_sigHandler
_waitForIpcSemaphore
_writeToIpcSegment
_writeVariable
getLastAlive
getPid
getVariable
isRunning
setVariable
start
stop

Description

ZendX_Console_Process_Unix allows you to spawn a class as a separated process

Constants

VOID_METHOD

 VOID_METHOD = 'void_method'

Void method

Details

value
void_method

RETURN_METHOD

 RETURN_METHOD = 'void_method'

Return method

Details

value
void_method

Properties

$_guid

integer $_guid = 'null'

GUID of the child process owner

Details

integer
visibility
private
default
null
final
false
static
false

$_internalIpcData

array $_internalIpcData = 'array'

A data structure to hold data for Inter Process Communications

Details

array
visibility
private
default
array
final
false
static
false

$_internalIpcKey

integer $_internalIpcKey = ''

Key to access to Shared Memory Area.

Details

integer
visibility
private
default
final
false
static
false

$_internalSemKey

integer $_internalSemKey = ''

Key to access to Sync Semaphore.

Details

integer
visibility
private
default
final
false
static
false

$_ipcIsOkay

boolean $_ipcIsOkay = ''

Is Shared Memory Area OK? If not, the start() method will block.

Otherwise we'll have a running child without any communication channel.

Details

boolean
visibility
private
default
final
false
static
false

$_ipcSegFile

string $_ipcSegFile = ''

Filename of the IPC segment file

Details

string
visibility
private
default
final
false
static
false

$_ipcSemFile

string $_ipcSemFile = ''

Filename of the semaphor file

Details

string
visibility
private
default
final
false
static
false

$_isChild

boolean $_isChild = 'false'

Wether we are into child process or not

Details

boolean
visibility
private
default
false
final
false
static
false

$_isRunning

boolean $_isRunning = 'false'

Whether the process is yet forked or not

Details

boolean
visibility
private
default
false
final
false
static
false

$_name

string $_name = ''

Unique thread name

Details

string
visibility
private
default
final
false
static
false

$_pid

integer $_pid = 'null'

PID of the child process

Details

integer
visibility
private
default
null
final
false
static
false

$_puid

integer $_puid = 'null'

UID of the child process owner

Details

integer
visibility
private
default
null
final
false
static
false

Methods

__construct

__construct( integer $puid = null, integer $guid = null, integer $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.

Arguments
$puid
integer
$guid
integer
$umask
integer

__destruct

__destruct( ) :

Stop the child on destruction

Details
visibility
public
final
false
static
false

_callCallbackMethod

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

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

Arguments
$methodName
string
$argList
array
$type
string
Output
mixed
Details
visibility
protected
final
false
static
false

_cleanProcessContext

_cleanProcessContext( ) : void

Destroy thread context and free relative resources.

Details
visibility
private
final
false
static
false

_createIpcSegment

_createIpcSegment( ) : boolean

Create an IPC segment

Output
boolean
Details
visibility
private
final
false
static
false
throws
When SHM segment can't be created

_createIpcSemaphore

_createIpcSemaphore( ) : boolean

Create IPC semaphore

Output
boolean
Details
visibility
private
final
false
static
false
throws
When semaphore can't be created

_readFromIpcSegment

_readFromIpcSegment( ) : void

Read data from IPC segment

Details
visibility
private
final
false
static
false
throws
When writing of SHM segment fails

_run

_run( ) : void

This method actually implements the pseudo-thread logic.

Details
visibility
protected
final
false
static
false

_sendSigUsr1

_sendSigUsr1( ) : void

Sends signal to the child process

Details
visibility
private
final
false
static
false

_setAlive

_setAlive( ) : void

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

Details
visibility
protected
final
false
static
false

_sigHandler

_sigHandler( integer $signo ) : void

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

Arguments
$signo
integer
Details
visibility
private
final
false
static
false

_waitForIpcSemaphore

_waitForIpcSemaphore( ) : void

Wait for IPC Semaphore

Details
visibility
private
final
false
static
false

_writeToIpcSegment

_writeToIpcSegment( ) : void

Write data to IPC segment

Details
visibility
private
final
false
static
false
throws
When writing of SHM segment fails

_writeVariable

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

Acutally Write a variable to the shared memory segment

Arguments
$name
string
$value
mixed
Details
visibility
private
final
false
static
false

getLastAlive

getLastAlive( ) : integer

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.

Output
integer
Details
visibility
public
final
false
static
false

getPid

getPid( ) : integer

Returns the PID of the current pseudo-thread.

Output
integer
Details
visibility
public
final
false
static
false

getVariable

getVariable( string $name ) : mixed

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

Arguments
$name
string
Output
mixed
Details
visibility
public
final
false
static
false

isRunning

isRunning( ) : boolean

Test if the pseudo-thread is already started.

Output
boolean
Details
visibility
public
final
false
static
false

setVariable

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

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
string
$value
mixed
Details
visibility
public
final
false
static
false
throws
When an invalid variable name is supplied

start

start( ) : void

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

Details
visibility
public
final
false
static
false
throws
When SHM segments can't be created
throws
When process forking fails

stop

stop( ) : boolean

Causes the current thread to die.

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

Output
boolean
Details
visibility
public
final
false
static
false
Documentation was generated by DocBlox 0.12.2.