mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 05:26:57 +08:00
197 lines
7.2 KiB
HTML
197 lines
7.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<title>Create or open shared memory block</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.shmop-open" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">shmop_open</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.0.4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">shmop_open</span> — <span class="dc-title">Create or open shared memory block</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.shmop-open-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>shmop_open</strong></span>
|
|
( <span class="methodparam"><span class="type">int</span> <code class="parameter">$key</code></span>
|
|
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$flags</code></span>
|
|
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code></span>
|
|
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code></span>
|
|
) : <span class="type">resource</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
<span class="function"><strong>shmop_open()</strong></span> can create or open a shared memory block.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.shmop-open-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">key</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
System's id for the shared memory block.
|
|
Can be passed as a decimal or hex.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">flags</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The flags that you can use:
|
|
<ul class="itemizedlist">
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"a" for access (sets SHM_RDONLY for shmat)
|
|
use this flag when you need to open an existing shared memory
|
|
segment for read only
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"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
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"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.
|
|
</span>
|
|
</li>
|
|
<li class="listitem">
|
|
<span class="simpara">
|
|
"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.
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">mode</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
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 example <em>0644</em>
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">size</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
The size of the shared memory block you wish to create in bytes
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
Note: the 3rd and 4th should be entered as 0 if you are opening an
|
|
existing memory segment.
|
|
</p>
|
|
</p></blockquote>
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.shmop-open-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
On success <span class="function"><strong>shmop_open()</strong></span> will return an resource that you can
|
|
use to access the shared memory segment you've created. <strong><code>FALSE</code></strong> is
|
|
returned on failure.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.shmop-open-changelog">
|
|
<h3 class="title">更新日志</h3>
|
|
<table class="doctable informaltable">
|
|
|
|
<thead>
|
|
<tr>
|
|
<th>版本</th>
|
|
<th>说明</th>
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody class="tbody">
|
|
<tr>
|
|
<td>7.0.0</td>
|
|
<td>
|
|
The return type of <span class="function"><strong>shmop_open()</strong></span> has been changed from
|
|
<span class="type"><a href="language.types.integer.html" class="type int">int</a></span> to <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>.
|
|
</td>
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.shmop-open-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-4457">
|
|
<p><strong>Example #1 Create a new shared memory block</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$shm_key </span><span style="color: #007700">= </span><span style="color: #0000BB">ftok</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">, </span><span style="color: #DD0000">'t'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$shm_id </span><span style="color: #007700">= </span><span style="color: #0000BB">shmop_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$shm_key</span><span style="color: #007700">, </span><span style="color: #DD0000">"c"</span><span style="color: #007700">, </span><span style="color: #0000BB">0644</span><span style="color: #007700">, </span><span style="color: #0000BB">100</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
<p class="para">
|
|
This example opened a shared memory block with a system id returned by
|
|
<span class="function"><a href="ftok.html" class="function">ftok()</a></span>.
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.shmop-open-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="shmop_close.html" class="function" rel="rdfs-seeAlso">shmop_close()</a> - Close shared memory block</span></li>
|
|
<li class="member"><span class="function"><a href="shmop_delete.html" class="function" rel="rdfs-seeAlso">shmop_delete()</a> - Delete shared memory block</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |