PHP Class Icicle\Concurrent\Sync\SharedMemoryParcel

A shared object is a container that stores an object inside shared memory. The object can be accessed and mutated by any thread or process. The shared object handle itself is serializable and can be sent to any thread or process to give access to the value that is shared in the container. Because each shared object uses its own shared memory segment, it is much more efficient to store a larger object containing many values inside a single shared container than to use many small shared containers. Note that accessing a shared object is not atomic. Access to a shared object should be protected with a mutex to preserve data integrity. When used with forking, the object must be created prior to forking for both processes to access the synchronized object.
See also: http://php.net/manual/en/book.shmop.php The shared memory extension.
See also: http://man7.org/linux/man-pages/man2/shmctl.2.html How shared memory works on Linux.
See also: https://msdn.microsoft.com/en-us/library/ms810613.aspx How shared memory works on Windows.
Inheritance: implements Icicle\Concurrent\Sync\Parcel, implements Serializable
Show file Open project: icicleio/concurrent

Public Methods

Method Description
__clone ( )
__construct ( mixed $value, integer $size = 16384, integer $permissions = 384 ) Creates a new local object container.
__debugInfo ( ) : array Gets information about the object for debugging purposes.
free ( ) Frees the shared object from memory.
isFreed ( ) : boolean Checks if the object has been freed.
serialize ( ) : string Serializes the local object handle.
synchronized ( callable $callback ) : Generator
unserialize ( string $serialized ) Unserializes the local object handle.
unwrap ( )

Protected Methods

Method Description
wrap ( $value ) If the value requires more memory to store than currently allocated, a new shared memory segment will be allocated with a larger size to store the value in. The previous memory segment will be cleaned up and marked for deletion. Other processes and threads will be notified of the new memory segment on the next read attempt. Once all running processes and threads disconnect from the old segment, it will be freed by the OS.

Private Methods

Method Description
getHeader ( ) : array Reads and returns the data header at the current memory segment.
handleMovedMemory ( ) Updates the current memory segment handle, handling any moves made on the data.
init ( mixed $value, integer $size = 16384, integer $permissions = 384 )
memDelete ( ) Requests the shared memory segment to be deleted.
memGet ( integer $offset, integer $size ) : string Reads binary data from shared memory.
memOpen ( integer $key, string $mode, integer $permissions, integer $size ) Opens a shared memory handle.
memSet ( integer $offset, string $data ) Writes binary data to shared memory.
setHeader ( integer $state, integer $size, integer $permissions ) Sets the header data for the current memory segment.

Method Details

__clone() public method

public __clone ( )

__construct() public method

The object given will be assigned a new object ID and will have a reference to it stored in memory local to the thread.
public __construct ( mixed $value, integer $size = 16384, integer $permissions = 384 )
$value mixed The value to store in the container.
$size integer The number of bytes to allocate for the object. If not specified defaults to 16384 bytes.
$permissions integer The access permissions to set for the object. If not specified defaults to 0600.

__debugInfo() public method

Gets information about the object for debugging purposes.
public __debugInfo ( ) : array
return array An array of debugging information.

free() public method

The memory containing the shared value will be invalidated. When all process disconnect from the object, the shared memory block will be destroyed by the OS. Calling free() on an object already freed will have no effect.
public free ( )

isFreed() public method

Note that this does not check if the object has been destroyed; it only checks if this handle has freed its reference to the object.
public isFreed ( ) : boolean
return boolean True if the object is freed, otherwise false.

serialize() public method

Note that this does not serialize the object that is referenced, just the object handle.
public serialize ( ) : string
return string The serialized object handle.

synchronized() public method

public synchronized ( callable $callback ) : Generator
$callback callable
return Generator

unserialize() public method

Unserializes the local object handle.
public unserialize ( string $serialized )
$serialized string The serialized object handle.

unwrap() public method

public unwrap ( )

wrap() protected method

If the value requires more memory to store than currently allocated, a new shared memory segment will be allocated with a larger size to store the value in. The previous memory segment will be cleaned up and marked for deletion. Other processes and threads will be notified of the new memory segment on the next read attempt. Once all running processes and threads disconnect from the old segment, it will be freed by the OS.
protected wrap ( $value )