Shared Memory 函数
在线手册:中文  英文

shmop_delete

(PHP 4 >= 4.0.4, PHP 5)

shmop_deleteDelete shared memory block

说明

bool shmop_delete ( int $shmid )

shmop_delete() is used to delete a shared memory block.

参数

shmid

The shared memory block identifier created by shmop_open()

返回值

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

范例

Example #1 Deleting shared memory block

<?php
shmop_delete
($shm_id);
?>

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


Shared Memory 函数
在线手册:中文  英文

用户评论:

lizzy (2004-10-12 19:19:17)

A helpful hint, although when using shmop on windows (yes you can use shmop on windows in IIS or Apache when used as isapi/module) you can delete a segment and later open a new segment with the SAME KEY in the same script no problem, YOU CANNOT IN LINUX/UNIX - the segment will still exist - it's not immediately deleted - but will be marked for deletion and you'll get errors when trying to create the new one - just a reminder.

slavapl at mailandnews dot com (2001-05-02 12:27:01)

There is an important factor to keep in mind here, the shmop_delete function doesn't actually "delete" the memory segment per say, it MARKS the segment for deletion. An shm segment can not be deleted while there are processes attached to it, so a call to shm_delete will two things, first no other processes will be allowed to attach to the segment after this call, and also, it will mark the segment for deletion, which means that when all current processes mapping the segment detach (shmop_close) the system will automatically delete the segment.
So, again, the proper way to close and delete an shm segement is:
$shmid = shmop_open(...);
(do something with the block here: read, write, whatever)
shmop_delete($shmid);
shmop_close($shmid);
you must call the shmop_delete before you call shmop_close for reasons outlined above.
Also to mark a segment for deletion you must be root or the owner.
A few notes from the linux manpage on shmctl:
IPC_RMID (the flag used in shmop_delete):
is used to mark the segment as destroyed. It will actually be destroyed after the last detach. (I.e., when the shm_nattch member of the associated structure shmid_ds is zero.) The user must be the owner, creator, or the super-user.
***
The user must ensure that a segment is eventually destroyed; otherwise its pages that were faulted in will remain in memory or swap.
***

易百教程