Console/Process/Unix.php

Show: PublicProtectedPrivateinherited
Table of Contents
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.
Category
ZendX  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
ZendX_Console  
Version
$Id$  

\ZendX_Console_Process_Unix

Package: ZendX_Console
ZendX_Console_Process_Unix allows you to spawn a class as a separated process
Category
ZendX  
Copyright
Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Constants

>VConstant  VOID_METHOD = 'void_method'
Void method
>VConstant  RETURN_METHOD = 'void_method'
Return method

Properties

>VPropertyprivateinteger $_guid = null
GUID of the child process owner
Default valuenullDetails
Type
integer
>VPropertyprivatearray $_internalIpcData = array()
A data structure to hold data for Inter Process Communications
Default valuearray()Details
Type
array
>VPropertyprivateinteger $_internalIpcKey
Key to access to Shared Memory Area.
Details
Type
integer
>VPropertyprivateinteger $_internalSemKey
Key to access to Sync Semaphore.
Details
Type
integer
>VPropertyprivateboolean $_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
Type
boolean
>VPropertyprivatestring $_ipcSegFile
Filename of the IPC segment file
Details
Type
string
>VPropertyprivatestring $_ipcSemFile
Filename of the semaphor file
Details
Type
string
>VPropertyprivateboolean $_isChild = false
Wether we are into child process or not
Default valuefalseDetails
Type
boolean
>VPropertyprivateboolean $_isRunning = false
Whether the process is yet forked or not
Default valuefalseDetails
Type
boolean
>VPropertyprivatestring $_name
Unique thread name
Details
Type
string
>VPropertyprivateinteger $_pid = null
PID of the child process
Default valuenullDetails
Type
integer
>VPropertyprivateinteger $_puid = null
UID of the child process owner
Default valuenullDetails
Type
integer

Methods

methodpublic__construct(integer $puid = null, integer $guid = null, integer $umask = null) : void

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
NameTypeDescription
$puidinteger
$guidinteger
$umaskinteger
Throws
ExceptionDescription
\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
methodpublic__destruct() : void

Stop the child on destruction

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

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

Parameters
NameTypeDescription
$methodNamestring
$argListarray
$typestring
Returns
TypeDescription
mixed
methodprivate_cleanProcessContext() : void

Destroy thread context and free relative resources.

methodprivate_createIpcSegment() : boolean

Create an IPC segment

Returns
TypeDescription
boolean
Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen SHM segment can't be created
methodprivate_createIpcSemaphore() : boolean

Create IPC semaphore

Returns
TypeDescription
boolean
Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen semaphore can't be created
methodprivate_readFromIpcSegment() : void

Read data from IPC segment

Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen writing of SHM segment fails
methodprotected_run() : void
abstract

This method actually implements the pseudo-thread logic.

methodprivate_sendSigUsr1() : void

Sends signal to the child process

methodprotected_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...
methodprivate_sigHandler(integer $signo) : void

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

Parameters
NameTypeDescription
$signointeger
methodprivate_waitForIpcSemaphore() : void

Wait for IPC Semaphore

methodprivate_writeToIpcSegment() : void

Write data to IPC segment

Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen writing of SHM segment fails
methodprivate_writeVariable(string $name, mixed $value) : void

Acutally Write a variable to the shared memory segment

Parameters
NameTypeDescription
$namestring
$valuemixed
methodpublicgetLastAlive() : 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.
Returns
TypeDescription
integer
methodpublicgetPid() : integer

Returns the PID of the current pseudo-thread.

Returns
TypeDescription
integer
methodpublicgetVariable(string $name) : mixed

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

Parameters
NameTypeDescription
$namestring
Returns
TypeDescription
mixed
methodpublicisRunning() : boolean

Test if the pseudo-thread is already started.

Returns
TypeDescription
boolean
methodpublicsetVariable(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.

Parameters
NameTypeDescription
$namestring
$valuemixed
Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen an invalid variable name is supplied
methodpublicstart() : 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).
Throws
ExceptionDescription
\ZendX_Console_Process_ExceptionWhen SHM segments can't be created
\ZendX_Console_Process_ExceptionWhen process forking fails
methodpublicstop() : boolean

Causes the current thread to die.

The relative process is killed and disappears immediately from the processes list.
Returns
TypeDescription
boolean
Documentation was generated by phpDocumentor 2.2.0 .