A preliminary study on php shared memory shmop

WBOY
Release: 2016-07-28 08:25:35
Original
1560 people have browsed it

First go to the reading and writing program:

<?php
/**
  * SHMOP共享内存操作示例
  * @author monkee
 **/
$key = 0x4337b700;
$size = 4096;
$shmid = @shmop_open($key, &#39;c&#39;, 0644, $size);
if($shmid === FALSE){
	exit(&#39;shmop_open error!&#39;);
}

$data = &#39;世界,你好!我将写入很多的数据,你能罩得住么?&#39;;

$length = shmop_write($shmid, pack(&#39;a*&#39;,$data), 0);
if($length === FALSE){
	exit(&#39;shmop_write error!&#39;);
}

@shmop_close($shmid);

exit(&#39;succ&#39;);
?>
Copy after login

Read:

<?php
/**
  * SHMOP共享内存操作示例
  * @author monkee
 **/
$key = 0x4337b700;
$size = 256;
$shmid = @shmop_open($key, &#39;c&#39;, 0644, $size);
if($shmid === FALSE){
	exit(&#39;shmop_open error!&#39;);
}

$data = unpack(&#39;a*&#39;, shmop_read($shmid, 0, 256));
if($data === FALSE){
	exit(&#39;shmop_read error!&#39;);
}
@shmop_close($shmid);

exit($data[1]);
?>
Copy after login
unix/linux command view:

 php共享内存shmop初探

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!