Ref/shmop-Phpdoc专题

shmop_close

Close shared memory block

说明

void <span class="methodname">shmop_close ( <span class="type">Shmop $shmop )

shmop_close is used to close a shared memory block.

参数

shmop
The shared memory block resource created by <span class="function">shmop_open

返回值

没有返回值。

更新日志

版本 说明
8.0.0 shmop expects a Shmop instance now; previously, a resource was expected.

范例

示例 #1 Closing shared memory block

<?php
shmop_close($shm_id);
?>

This example will close shared memory block identified by $shm_id.

参见

  • shmop_open

shmop_delete

Delete shared memory block

说明

bool <span class="methodname">shmop_delete ( <span class="methodparam">Shmop $shmop )

shmop_delete is used to delete a shared memory block.

参数

shmop
The shared memory block resource created by <span class="function">shmop_open

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 shmop expects a Shmop instance now; previously, a resource was expected.

范例

示例 #1 Deleting shared memory block

<?php
shmop_delete($shm_id);
?>

This example will delete shared memory block identified by $shm_id.

shmop_open

Create or open shared memory block

说明

Shmop<span class="type">false <span class="methodname">shmop_open ( <span class="type">int $key , <span class="type">string $mode , <span class="methodparam">int $permissions , int $size )

shmop_open can create or open a shared memory block.

参数

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

mode
The flags that you can use:

  • "a" for access (sets SHM_RDONLY for shmat) use this flag when you need to open an existing shared memory segment for read only
  • "c" for create (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
  • "w" for read & write access use this flag when you need to read and write to a shared memory segment, use this flag in most cases.
  • "n" create a new memory segment (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. Permissions need to be passed in octal form, like for example 0644

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

Note:

Note: the 3rd and 4th should be entered as 0 if you are opening an existing memory segment.

返回值

On success shmop_open will return a <span class="classname">Shmop instance that you can use to access the shared memory segment you've created. false is returned on failure.

更新日志

版本 说明
8.0.0 On success, this function returns an Shmop instance now; previously, a resource was returned.

范例

示例 #1 Create a new shared memory block

<?php
$shm_key = ftok(__FILE__, 't');
$shm_id = shmop_open($shm_key, "c", 0644, 100);
?>

This example opened a shared memory block with a system id returned by ftok.

参见

  • shmop_close
  • shmop_delete

shmop_read

Read data from shared memory block

说明

string <span class="methodname">shmop_read ( <span class="type">Shmop $shmop , <span class="methodparam">int $offset , int $size )

shmop_read will read a string from shared memory block.

参数

shmop
The shared memory block identifier created by <span class="function">shmop_open

offset
Offset from which to start reading

size
The number of bytes to read. 0 reads shmop_size($shmid) - $start bytes.

返回值

Returns the data 或者在失败时返回 false.

更新日志

版本 说明
8.0.0 shmop expects a Shmop instance now; previously, a resource was expected.

范例

示例 #1 Reading shared memory block

<?php
$shm_data = shmop_read($shm_id, 0, 50);
?>

This example will read 50 bytes from shared memory block and place the data inside $shm_data.

参见

  • shmop_write

shmop_size

Get size of shared memory block

说明

int <span class="methodname">shmop_size ( <span class="type">Shmop $shmop )

shmop_size is used to get the size, in bytes of the shared memory block.

参数

shmop
The shared memory block identifier created by <span class="function">shmop_open

返回值

Returns an int, which represents the number of bytes the shared memory block occupies.

更新日志

版本 说明
8.0.0 shmop expects a Shmop instance now; previously, a resource was expected.

范例

示例 #1 Getting the size of the shared memory block

<?php
$shm_size = shmop_size($shm_id);
?>

This example will put the size of shared memory block identified by $shm_id into $shm_size.

shmop_write

Write data into shared memory block

说明

int <span class="methodname">shmop_write ( <span class="type">Shmop $shmop , <span class="methodparam">string $data , int $offset )

shmop_write will write a string into shared memory block.

参数

shmop
The shared memory block identifier created by <span class="function">shmop_open

data
A string to write into shared memory block

offset
Specifies where to start writing data inside the shared memory segment.

返回值

The size of the written data.

更新日志

版本 说明
8.0.0 Prior to PHP 8.0.0, false was returned on failure.
8.0.0 shmop expects a Shmop instance now; previously, a resource was expected.

范例

示例 #1 Writing to shared memory block

<?php
$shm_bytes_written = shmop_write($shm_id, $my_string, 0);
?>

This example will write data inside $my_string into shared memory block, $shm_bytes_written will contain the number of bytes written.

参见

  • shmop_read

目录


本站为非盈利网站,作品由网友提供上传,如无意中有侵犯您的版权,请联系删除