略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: shm_remove

2024-03-27

shm_remove

(PHP 4, PHP 5, PHP 7, PHP 8)

shm_removeRemoves shared memory from Unix systems

说明

shm_remove(SysvSharedMemory $shm): bool

shm_remove() removes the shared memory shm. All data will be destroyed.

参数

shm

A shared memory segment obtained from shm_attach().

返回值

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

更新日志

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

参见

add a noteadd a note

User Contributed Notes 3 notes

up
1
aaron DURP segura DURP gmail DURP com
15 years ago
It appears that you must be connected to the shm segment in order to remove it.

<?php
shm_remove
($shm);
shm_detach($shm);
?>

works, while

<?php
shm_detach
($shm);
shm_remove($shm);
?>

produces "Warning: shm_remove(): The parameter is not a valid shm_identifier ..."
up
0
HansRich
8 years ago
WARNING: this function WILL NOT destroy the memory segment if there are other processes attached to it, but it will return TRUE anyways!

You will have to try to access the segment again after destroying it to make sure it was relly destroyed.
up
-1
cu at ulakbim dot gov dot tr
22 years ago
Though it says **shm_identifier** in
  int shm_remove(int shm_identifier);
and
  shm_attach() returns an **id** that that can be used to access the System V...

a snippet like this:
<?php
  $key
= 1234;
 
$shm=shm_attach($key);
 
// do whatever...
 
shm_remove($shm);
?>

produces an error like
Warning: 2(which is the value of $shm) is not a existing SysV shared memory key in /usr/cu/web/sema.php on line 44...

The documentation confused me a bit. I thought shm_remove would get the shm handle/id that returns from shm_attach, not the key given to shm_attach. So, use instead:
  shm_remove($key);

which is what is intended indeed.

官方地址:https://www.php.net/manual/en/function.shm-remove.php

冷却塔厂家 广告
-- 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3