Back to index

d-push  2.0
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes
InterProcessData Class Reference
Inheritance diagram for InterProcessData:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 InterProcessData ()
 Constructor.
 InitializeParams ()
 Initializes internal parameters.
 ReInitSharedMem ()
 Reinitializes shared memory by removing, detaching and re-allocating it.
 Clean ()
 Cleans up the shared memory block.
 IsActive ()
 Indicates if the shared memory is active.

Public Attributes

const CLEANUPTIME = 1

Protected Member Functions

 blockMutex ()
 Blocks the class mutex Method blocks until mutex is available! ATTENTION: make sure that you always release a blocked mutex!
 releaseMutex ()
 Releases the class mutex After the release other processes are able to block the mutex themselfs.
 hasData ($id=2)
 Indicates if the requested variable is available in shared memory.
 getData ($id=2)
 Returns the requested variable from shared memory.
 setData ($data, $id=2)
 Writes the transmitted variable to shared memory Subclasses may never use an id < 2!

Protected Attributes

 $type
 $allocate

Static Protected Attributes

static $devid
static $pid
static $user
static $start

Private Member Functions

 InitSharedMem ()
 Allocates shared memory.
 RemoveSharedMem ()
 Removes and detaches shared memory.
 setInitialCleanTime ()
 Sets the time when the shared memory block was created.

Private Attributes

 $mutexid
 $memid

Detailed Description

Definition at line 45 of file interprocessdata.php.


Member Function Documentation

Blocks the class mutex Method blocks until mutex is available! ATTENTION: make sure that you always release a blocked mutex!

protected

Returns:
boolean

Definition at line 200 of file interprocessdata.php.

                                    {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @sem_acquire($this->mutexid);

        return false;
    }

Here is the caller graph for this function:

Cleans up the shared memory block.

public

Returns:
boolean

Definition at line 166 of file interprocessdata.php.

                            {
        $stat = false;

        // exclusive block
        if ($this->blockMutex()) {
            $cleanuptime = ($this->hasData(1)) ? $this->getData(1) : false;

            // TODO implement Shared Memory cleanup

            $this->releaseMutex();
        }
        // end exclusive block

        return $stat;
    }

Here is the call graph for this function:

InterProcessData::getData ( id = 2) [protected]

Returns the requested variable from shared memory.

Parameters:
int$idint indicating the variable

protected

Returns:
mixed

Definition at line 249 of file interprocessdata.php.

                                        {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @shm_get_var($this->memid, $id);

        return ;
    }

Here is the caller graph for this function:

InterProcessData::hasData ( id = 2) [protected]

Indicates if the requested variable is available in shared memory.

Parameters:
int$idint indicating the variable

protected

Returns:
boolean

Definition at line 229 of file interprocessdata.php.

                                        {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false)) {
            if (function_exists("shm_has_var"))
                return @shm_has_var($this->memid, $id);
            else {
                $some = $this->getData($id);
                return isset($some);
            }
        }
        return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Initializes internal parameters.

public

Returns:
boolean

Definition at line 76 of file interprocessdata.php.

                                       {
        if (!isset(self::$devid)) {
            self::$devid = Request::GetDeviceID();
            self::$pid = @getmypid();
            self::$user = Request::GetAuthUser();
            self::$start = time();
        }
        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Allocates shared memory.

private

Returns:
boolean

Definition at line 92 of file interprocessdata.php.

                                     {
        // shared mem general "turn off switch"
        if (defined("USE_SHARED_MEM") && USE_SHARED_MEM === false) {
            ZLog::Write(LOGLEVEL_INFO, "InterProcessData::InitSharedMem(): the usage of shared memory for Z-Push has been disabled. Check your config for 'USE_SHARED_MEM'.");
            return false;
        }

        if (!function_exists('sem_get') || !function_exists('shm_attach') || !function_exists('sem_acquire')|| !function_exists('shm_get_var')) {
            ZLog::Write(LOGLEVEL_INFO, "InterProcessData::InitSharedMem(): PHP libraries for the use shared memory are not available. Functionalities like z-push-top or loop detection are not available. Check your php packages.");
            return false;
        }

        // Create mutex
        $this->mutexid = @sem_get($this->type, 1);
        if ($this->mutexid === false) {
            ZLog::Write(LOGLEVEL_ERROR, "InterProcessData::InitSharedMem(): could not aquire semaphore");
            return false;
        }

        // Attach shared memory
        $this->memid = shm_attach($this->type+10, $this->allocate);
        if ($this->memid === false) {
            ZLog::Write(LOGLEVEL_ERROR, "InterProcessData::InitSharedMem(): could not attach shared memory");
            @sem_remove($this->mutexid);
            $this->mutexid = false;
            return false;
        }

        // TODO mem cleanup has to be implemented
        //$this->setInitialCleanTime();

        return true;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Constructor.

public

Definition at line 62 of file interprocessdata.php.

                                       {
        if (!isset($this->type) || !isset($this->allocate))
            throw new FatalNotImplementedException(sprintf("Class InterProcessData can not be initialized. Subclass %s did not initialize type and allocable memory.", get_class($this)));

        if ($this->InitSharedMem())
            ZLog::Write(LOGLEVEL_DEBUG, sprintf("%s(): Initialized mutexid %s and memid %s.", get_class($this), $this->mutexid, $this->memid));
    }

Here is the call graph for this function:

Indicates if the shared memory is active.

public

Returns:
boolean

Definition at line 188 of file interprocessdata.php.

                               {
        return ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false));
    }

Here is the caller graph for this function:

Reinitializes shared memory by removing, detaching and re-allocating it.

public

Returns:
boolean

Definition at line 156 of file interprocessdata.php.

                                      {
        return ($this->RemoveSharedMem() && $this->InitSharedMem());
    }

Here is the call graph for this function:

Releases the class mutex After the release other processes are able to block the mutex themselfs.

protected

Returns:
boolean

Definition at line 214 of file interprocessdata.php.

                                      {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @sem_release($this->mutexid);

        return false;
    }

Here is the caller graph for this function:

Removes and detaches shared memory.

private

Returns:
boolean

Definition at line 132 of file interprocessdata.php.

                                       {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false)) {
            @sem_acquire($this->mutexid);
            $memid = $this->memid;
            $this->memid = false;
            @sem_release($this->mutexid);

            @sem_remove($this->mutexid);
            @shm_remove($memid);
            @shm_detach($memid);

            $this->mutexid = false;

            return true;
        }
        return false;
    }

Here is the caller graph for this function:

InterProcessData::setData ( data,
id = 2 
) [protected]

Writes the transmitted variable to shared memory Subclasses may never use an id < 2!

Parameters:
mixed$datadata which should be saved into shared memory
int$idint indicating the variable (bigger than 2!)

protected

Returns:
boolean

Definition at line 266 of file interprocessdata.php.

                                               {
        if ((isset($this->mutexid) && $this->mutexid !== false) && (isset($this->memid) && $this->memid !== false))
            return @shm_put_var($this->memid, $id, $data);

        return false;
    }

Here is the caller graph for this function:

Sets the time when the shared memory block was created.

private

Returns:
boolean

Definition at line 279 of file interprocessdata.php.

                                           {
        $stat = false;

        // exclusive block
        if ($this->blockMutex()) {

            if ($this->hasData(1) == false)
                $stat = $this->setData(time(), 1);

            $this->releaseMutex();
        }
        // end exclusive block

        return $stat;
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 53 of file interprocessdata.php.

InterProcessData::$devid [static, protected]

Definition at line 48 of file interprocessdata.php.

Definition at line 55 of file interprocessdata.php.

Definition at line 54 of file interprocessdata.php.

InterProcessData::$pid [static, protected]

Definition at line 49 of file interprocessdata.php.

InterProcessData::$start [static, protected]

Definition at line 51 of file interprocessdata.php.

Definition at line 52 of file interprocessdata.php.

InterProcessData::$user [static, protected]

Definition at line 50 of file interprocessdata.php.

Definition at line 46 of file interprocessdata.php.


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