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 allows you to spawn a class as a separated process
VOID_METHOD = 'void_method'
Void method
RETURN_METHOD = 'void_method'
Return method
integer $_guid = 'null'
GUID of the child process owner
array $_internalIpcData = 'array'
A data structure to hold data for Inter Process Communications
integer $_internalIpcKey = ''
Key to access to Shared Memory Area.
integer $_internalSemKey = ''
Key to access to Sync Semaphore.
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.
string $_ipcSegFile = ''
Filename of the IPC segment file
string $_ipcSemFile = ''
Filename of the semaphor file
boolean $_isChild = 'false'
Wether we are into child process or not
boolean $_isRunning = 'false'
Whether the process is yet forked or not
string $_name = ''
Unique thread name
integer $_pid = 'null'
PID of the child process
integer $_puid = 'null'
UID of the child process owner
__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.
__destruct(
)
:
Stop the child on destruction
_callCallbackMethod(
string $methodName, array $argList
=
array, string $type
=
self
)
:
mixed
This is called from within the parent; all the communication stuff is done here.
_cleanProcessContext(
)
:
void
Destroy thread context and free relative resources.
_createIpcSegment(
)
:
boolean
Create an IPC segment
_createIpcSemaphore(
)
:
boolean
Create IPC semaphore
_readFromIpcSegment(
)
:
void
Read data from IPC segment
_run(
)
:
void
This method actually implements the pseudo-thread logic.
_sendSigUsr1(
)
:
void
Sends signal to the child process
_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...
_sigHandler(
integer $signo
)
:
void
This is the signal handler that makes the communications between client and server possible.
_waitForIpcSemaphore(
)
:
void
Wait for IPC Semaphore
_writeToIpcSegment(
)
:
void
Write data to IPC segment
_writeVariable(
string $name, mixed $value
)
:
void
Acutally Write a variable to the shared memory segment
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.
getPid(
)
:
integer
Returns the PID of the current pseudo-thread.
getVariable(
string $name
)
:
mixed
Get a variable from the shared memory segment. Returns NULL if the variable doesn't exist.
isRunning(
)
:
boolean
Test if the pseudo-thread is already started.
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.
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).
stop(
)
:
boolean
Causes the current thread to die.
The relative process is killed and disappears immediately from the processes list.