Block
in package
Table of Contents
Properties
- $id : int
- Holds the system id for the shared memory block
- $perms : int
- Holds the default permission (octal) that will be used in created memory blocks
- $shmid : int
- Holds the shared memory block id returned by shmop_open
- $file : string
Methods
- __construct() : mixed
- Shared memory block instantiation
- __destruct() : mixed
- Closes the shared memory block and stops manipulation
- delete() : mixed
- Mark a shared memory block for deletion
- exists() : bool
- Checks if a shared memory block with the provided id exists or not
- getId() : mixed
- Gets the current shared memory block id
- getPermissions() : mixed
- Gets the current shared memory block permissions
- read() : string
- Reads from a shared memory block
- setPermissions() : mixed
- Sets the default permission (octal) that will be used in created memory blocks
- write() : mixed
- Writes on a shared memory block
- generateID() : int
- Generates a random ID for a shared memory block
Properties
$id
Holds the system id for the shared memory block
protected
int
$id
Tags
$perms
Holds the default permission (octal) that will be used in created memory blocks
protected
int
$perms
= 0644
Tags
$shmid
Holds the shared memory block id returned by shmop_open
protected
int
$shmid
Tags
$file
private
string
$file
Methods
__construct()
Shared memory block instantiation
public
__construct([string $id = null ]) : mixed
In the constructor we'll check if the block we're going to manipulate already exists or needs to be created. If it exists, let's open it.
Parameters
- $id : string = null
-
(optional) ID of the shared memory block you want to manipulate
Tags
__destruct()
Closes the shared memory block and stops manipulation
public
__destruct() : mixed
Tags
delete()
Mark a shared memory block for deletion
public
delete() : mixed
Tags
exists()
Checks if a shared memory block with the provided id exists or not
public
exists(string $id) : bool
In order to check for shared memory existance, we have to open it with reading access. If it doesn't exist, warnings will be cast, therefore we suppress those with the @ operator.
Parameters
- $id : string
-
ID of the shared memory block you want to check
Tags
Return values
bool —True if the block exists, false if it doesn't
getId()
Gets the current shared memory block id
public
getId() : mixed
Tags
getPermissions()
Gets the current shared memory block permissions
public
getPermissions() : mixed
Tags
read()
Reads from a shared memory block
public
read() : string
Tags
Return values
string —The data read from the shared memory block
setPermissions()
Sets the default permission (octal) that will be used in created memory blocks
public
setPermissions(string $perms) : mixed
Parameters
- $perms : string
-
Permissions, in octal form
Tags
write()
Writes on a shared memory block
public
write(string $data) : mixed
First we check for the block existance, and if it doesn't, we'll create it. Now, if the block already exists, we need to delete it and create it again with a new byte allocation that matches the size of the data that we want to write there. We mark for deletion, close the semaphore and create it again.
Parameters
- $data : string
-
The data that you wan't to write into the shared memory block
Tags
generateID()
Generates a random ID for a shared memory block
protected
generateID() : int
Tags
Return values
int —System V IPC key generated from pathname and a project identifier