shmop_open() - shmop函数(共享内存)
shmop_open()
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
Create or open shared memory block
说明
shmop_open(int $key,string $flags,int $mode,int $size): resourceshmop_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.
$flagsThe 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.
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 example0644
$sizeThe 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.0 | The return type of shmop_open() has been changed from int to resource. |
范例
Create a new shared memory block
This example opened a shared memory block with a system id returned by ftok().
参见
shmop_close()
Close shared memory blockshmop_delete()
Delete shared memory block
On *nix systems shmop_open is able to create an "infinite" amount of segments when setting $key = 0. After executing the following command twice in an interactive shell php > $res = shmop_open(0,"n",0600,1024); list the memory segments currently present $ ipcs -m ------ Shared Memory Segments -------- key shmid owner perms bytes nattch status 0x00000000 2293762 user 600 1024 0 0x00000000 2326531 user 600 1024 0 For any integer 0 in conjunction with the flag "n" shmop_open works like documented. It fails.
There is a little ftok function. This function isn't included into php for windows so i've grabbed it directly from linux glibc 2.3.2 source code. I hope that this can be useful. There is the code: sorry for my english :)
I'm having the same issue affecting XP and described below, on Mac OS X Lion. To solve it, use before 'a' flag, then 'n'. Avoid 'c' flag.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!