shmop_delete

(PHP 4 >= 4.0.4, PHP 5)

shmop_delete -- Delete shared memory block

Description

bool shmop_delete ( int shmid )

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

shmop_delete() takes the shmid, which is the shared memory block identifier created by shmop_open(). On success 1 is returned, on failure 0 is returned.

例子 1. Deleting shared memory block

<?php
shmop_delete
($shm_id);
?>

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


add a note add a note User Contributed Notes
lizzy
13-Oct-2004 10:19
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
03-May-2001 03:27
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.
***