作者:韩韩韩韩韩海 | 来源:互联网 | 2023-05-19 16:56
版本:php-5.2.0-Win32
页面代码:
$words=array('aaa','bbb','ccc','ddd');
//申请共享内存空间
$shm_id = shmop_open(0xff3, "c", 0644, 10485760);
//序列化
$value = serialize($words);
//写入共享内存空间
shmop_write($shm_id, $value, 0);
//获取共享内存空间中的内容
$my_string = shmop_read($shm_id, 0, strlen($value));
shmop_close($shm_id);
?>
错误信息:
Fatal error: Call to undefined function shmop_open() in D:\wwwroot\php5_test\index.php on line 4
php.ini中已经取消了php_shmop.dll前面的分号,并重启了windows2000
5 个解决方案
shmop_open
(PHP 4 >= 4.0.4)
shmop_open -- Create or open shared memory block
Description
int shmop_open ( int key, string flags, int mode, int size)
shmop_open() can create or open a shared memory block.
shmop_open() takes 4 parameters: key, which is the system's id for the shared memory block, this parameter can be passed as a decimal or hex. The second parameter are the 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 third parameter is the mode, which are 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 ex. 0644. The last parameter is 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 id that you can use to access the shared memory segment you've created.
Example 1. Create a new shared memory block
$shm_id = shmop_open(0x0fff, "c", 0644, 100);
?>
This example opened a shared memory block with a system id of 0x0fff.
User Contributed Notes
shmop_open
macmaster@pobox.com
30-Mar-2001 12:15
the key is a LONG variable type, meaning that the key can only be eight (8)
bytes long, which can be too short if you're using any form of automagic
key generation (like a parsed filename)
Mitchell_Shnier@ieee.orgZ
07-Nov-2001 05:51
To check whether a particular shared memory segment is already created, you
need to concatenate the "a" and "c" flags. For example
(where $SystemKey is the Unix key used by the other process(es) with which
you want to share this memory segment)...
$shm_id = shmop_open($SystemKey, "ac", 0, 0);
if ($shm_id) {
#it is already created
} else {
#you need to create it with shmop_open using "c" only
}
Using only "a" does not work (just as using only IPC_EXCL in the
Unix shmget() call is meaningless). Also, use the ipcs shell command to
see your shared memory segments.
hackie@prohost.org
20-Jan-2002 05:04
All of the problems have been addressed in the CVS, in addition the a mode
now indeed DOES attach to the segment in readonly mode (i.e. SHM_RDONLY),
so using shm_write on it would fail with a warning. It has 2 new flags w
(read/write) and n (new segment IPC_CREAT|IPC_EXCL).
And a number of segfaults fixed :)
这是php.net提供的函数和一些网友使用心得
我的看法是
$shm_id=shmop_open("login","c",0644,2);----注意权限是0644也就是
6 4 4
写,执行 执行 执行
而你在第二个页面用$login=shmop_read($shm_id1,0,1)来”读“所以提示说
unable to attach or create shm segment on line 2
浅妄薄见,望与斟酌
重新装?我是手工安装的,说白了,就是直接把iis中的isapi加上