Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

shmop_open

Description

The shmop_open of Shmop for PHP creates or opens the shared memory block.

Syntax

shmop_open(
    int $key,
    string $mode,
    int $permissions,
    int $size
): Shmop|false

Parameters

key

System's id for the shared memory block. Can be passed as a decimal or hexadecimal.

mode

The flags that you can use:

FlagDescription
aaccess (sets SHM_RDONLY for shmat), use this flag when you need to open an existing shared memory segment for read only
ccreate (sets IPC_CREATE), use this flag when you need to create a new shared memory segment or if a segment with the same key exists, try to open it for read and write
wread & write, use this flag when you need to read and write to a shared memory segment, use this flag in most cases.
ncreate new (sets IPC_CREATE|IPC_EXCL), use this flag when you want to create a new shared memory segment but if one already exists with the same flag, fail. This is useful for security purposes, using this you can prevent race condition exploits.

permissions

The permissions that you wish to assign to your memory segment, those are the same as permission for a file. Must be passed as an octal. For example: 0o644 (notation: 0o, user: 6, group: 4, other: 4).

OctalDescription
0none
1execute
2write
3write and execute
4read
5read and execute
6read and write
7read and write and execute

size

The size of the shared memory block you wish to create in bytes.

Return

Returns a Shmop instance to access the shared memory segment on success or false on failure.

Examples

1 · key · number · decimal

<?

$key = 1234567890;
$mode = "a";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

2 · key · number · hexadecimal

<?

$key = 0x0123456789abcdef;
$mode = "a";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

3 · key · function · ftok

<?

$filename = __FILE__;
$project_id = "t";

$key = ftok($filename, $project_id);
$mode = "a";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

4 · key · function · fileinode

<?

$filename = __FILE__;

$key = fileinode($filename);
$mode = "a";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

5 · mode · a

<?

$filename = __FILE__;
$project_id = "t";

$key = ftok($filename, $project_id);
$mode = "a";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

6 · mode · c

<?

$filename = __FILE__;
$project_id = "t";

$key = ftok($filename, $project_id);
$mode = "c";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

7 · mode · w

<?

$filename = __FILE__;
$project_id = "t";

$key = ftok($filename, $project_id);
$mode = "w";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
object(Shmop)#1 (0) {
}

8 · mode · n

<?

$filename = __FILE__;
$project_id = "t";

$key = ftok($filename, $project_id);
$mode = "n";
$permissions = 0o644;
$size = 16;

$return = shmop_open($key, $mode, $permissions, $size);

var_dump($return);

?>
bool(false)
HomeMenu