shmop_close

Close shared memory block

说明

void shmop_close ( resource $shmid )

shmop_close is used to close a shared memory block.

参数

shmid
The shared memory block resource created by shmop_open

返回值

没有返回值。

更新日志

版本说明
7.0.0The type of shmid has been changed from int to resource.

范例

示例 #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 shmop_delete ( resource $shmid )

shmop_delete is used to delete a shared memory block.

参数

shmid
The shared memory block resource created by shmop_open

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

更新日志

版本说明
7.0.0The type of shmid has been changed from int to resource.

范例

示例 #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

说明

resource shmop_open ( int $key , string $flags , int $mode , 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.

flags
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.

mode
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 an resource that you can use to access the shared memory segment you've created. FALSE is returned on failure.

更新日志

版本说明
7.0.0The return type of shmop_open has been changed from int to resource.

范例

示例 #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 shmop_read ( resource $shmid , int $start , int $count )

shmop_read will read a string from shared memory block.

参数

shmid
The shared memory block identifier created by shmop_open

start
Offset from which to start reading

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

返回值

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

更新日志

版本说明
7.0.0The type of shmid has been changed from int to resource.

范例

示例 #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 shmop_size ( resource $shmid )

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

参数

shmid
The shared memory block identifier created by shmop_open

返回值

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

更新日志

版本说明
7.0.0The type of shmid has been changed from int to resource.

范例

示例 #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 shmop_write ( resource $shmid , string $data , int $offset )

shmop_write will write a string into shared memory block.

参数

shmid
The shared memory block identifier created by 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, or FALSE on failure.

更新日志

版本说明
7.0.0The type of shmid has been changed from int to resource.

范例

示例 #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

目录