PHP Doku:: Einen gemeinsamen Speicherblock löschen - function.shmop-delete.html

Verlauf / Chronik / History: (15) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzErweiterungen zur ProzesskontrolleShared MemoryShared Memory Funktionenshmop_delete

Ein Service von Reinhard Neidl - Webprogrammierung.

Shared Memory Funktionen

<<shmop_close

shmop_open>>

shmop_delete

(PHP 4 >= 4.0.4, PHP 5)

shmop_deleteEinen gemeinsamen Speicherblock löschen

Beschreibung

bool shmop_delete ( int $shmid )

shmop_delete() wird benutzt, um einen gemeinsamen Speicherbereich zu löschen.

Parameter-Liste

shmid

Der Bezeichner für den gemeinsamen Speicherblock, der von shmop_open() erzeugt wurde.

Rückgabewerte

Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.

Beispiele

Beispiel #1 Einen gemeinsamen Speicherblock löschen

<?php
shmop_delete
($shm_id);
?>

In diesem Beispiel wird der gemeinsame Speicherblock mit der Kennung $shm_id gelöscht.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
lizzy
13.10.2004 4: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
2.05.2001 21: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.
***



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)