Home >Backend Development >PHP Tutorial >A preliminary study on php shared memory shmop
First go to the reading and writing program:
<?php /** * SHMOP共享内存操作示例 * @author monkee **/ $key = 0x4337b700; $size = 4096; $shmid = @shmop_open($key, 'c', 0644, $size); if($shmid === FALSE){ exit('shmop_open error!'); } $data = '世界,你好!我将写入很多的数据,你能罩得住么?'; $length = shmop_write($shmid, pack('a*',$data), 0); if($length === FALSE){ exit('shmop_write error!'); } @shmop_close($shmid); exit('succ'); ?>
<?php /** * SHMOP共享内存操作示例 * @author monkee **/ $key = 0x4337b700; $size = 256; $shmid = @shmop_open($key, 'c', 0644, $size); if($shmid === FALSE){ exit('shmop_open error!'); } $data = unpack('a*', shmop_read($shmid, 0, 256)); if($data === FALSE){ exit('shmop_read error!'); } @shmop_close($shmid); exit($data[1]); ?>unix/linux command view:
key: the unique key value of the shared memory. The shared memory uses this key to determine which part you are reading. A piece of memory.
shmid: When using key to obtain memory, you get the value of this id. It serves as an identifier for the memory block you operate on.
owner: the user who created the shared memory block
perms: the read and write permissions of the shared memory, 8 is prohibited, can be 777, consistent with the read and write permissions of the file.
bytes: the size of the memory block
nattch: the number of processes connected to the memory block
status: current status, such as: dest, about to be deleted, etc.
The above has introduced a preliminary study on PHP shared memory shmop, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.