downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the Git repository for this website on git.php.net.

Source of: /manual/fa/function.stream-socket-pair.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'fa',
  ),
 
'this' =>
  array (
   
0 => 'function.stream-socket-pair.php',
   
1 => 'stream_socket_pair',
  ),
 
'up' =>
  array (
   
0 => 'ref.stream.php',
   
1 => 'Stream Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.stream-socket-get-name.php',
   
1 => 'stream_socket_get_name',
  ),
 
'next' =>
  array (
   
0 => 'function.stream-socket-recvfrom.php',
   
1 => 'stream_socket_recvfrom',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="function.stream-socket-pair" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_socket_pair</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0)</p><p class="refpurpose"><span class="refname">stream_socket_pair</span> &mdash; <span class="dc-title">
   Creates a pair of connected, indistinguishable socket streams
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-socket-pair-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><b>stream_socket_pair</b></span>
    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$domain</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$type</tt></span>
   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$protocol</tt></span>
   )</div>

  <p class="para rdfs-comment">
   <span class="function"><b>stream_socket_pair()</b></span> creates a pair of connected,
   indistinguishable socket streams. This function is commonly used in IPC
   (Inter-Process Communication).    
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-socket-pair-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><i><tt class="parameter">domain</tt></i></span>
     <dd>

      <p class="para">
       The protocol family to be used: <b><tt>STREAM_PF_INET</tt></b>,
       <b><tt>STREAM_PF_INET6</tt></b> or
       <b><tt>STREAM_PF_UNIX</tt></b>
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><i><tt class="parameter">type</tt></i></span>
     <dd>

      <p class="para">
       The type of communication to be used:
       <b><tt>STREAM_SOCK_DGRAM</tt></b>,
       <b><tt>STREAM_SOCK_RAW</tt></b>,
       <b><tt>STREAM_SOCK_RDM</tt></b>,
       <b><tt>STREAM_SOCK_SEQPACKET</tt></b> or
       <b><tt>STREAM_SOCK_STREAM</tt></b>
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><i><tt class="parameter">protocol</tt></i></span>
     <dd>

      <p class="para">
       The protocol to be used: <b><tt>STREAM_IPPROTO_ICMP</tt></b>,
       <b><tt>STREAM_IPPROTO_IP</tt></b>,
       <b><tt>STREAM_IPPROTO_RAW</tt></b>,
       <b><tt>STREAM_IPPROTO_TCP</tt></b> or
       <b><tt>STREAM_IPPROTO_UDP</tt></b>      
      </p>
     </dd>

    </dt>

   </dl>

  </p>
  <blockquote class="note"><p><b class="note">Note</b>:
   <span class="simpara">
    Please consult the <a href="stream.constants.php" class="link">Streams constant
     list</a> for further details on each constant.
   </span>
  </p></blockquote>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-socket-pair-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an <span class="type"><a href="language.types.array.php" class="type array">array</a></span> with the two socket resources on success, or
   <b><tt>FALSE</tt></b> on failure.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-socket-pair-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
   
     <thead valign="middle">
      <tr valign="middle">
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody valign="middle" class="tbody">
      <tr valign="middle">
       <td align="left">5.3.0</td>
       <td align="left">
        This function is now available on Windows platforms.
       </td>
      </tr>

     </tbody>
   
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-socket-pair-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3380">
    <p><b>Example #1 A <span class="function"><b>stream_socket_pair()</b></span> example</b></p>
    <div class="example-contents"><p>
     This example shows the basic usage of
     <span class="function"><b>stream_socket_pair()</b></span> in Inter-Process Comunication.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$sockets&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_socket_pair</span><span style="color: #007700">(</span><span style="color: #0000BB">STREAM_PF_UNIX</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_SOCK_STREAM</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_IPPROTO_IP</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pcntl_fork</span><span style="color: #007700">();<br /><br />if&nbsp;(</span><span style="color: #0000BB">$pid&nbsp;</span><span style="color: #007700">==&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'could&nbsp;not&nbsp;fork'</span><span style="color: #007700">);<br /><br />}&nbsp;else&nbsp;if&nbsp;(</span><span style="color: #0000BB">$pid</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;parent&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"child&nbsp;PID:&nbsp;</span><span style="color: #0000BB">$pid</span><span style="color: #DD0000">\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /><br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;child&nbsp;*/<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">],&nbsp;</span><span style="color: #DD0000">"message&nbsp;from&nbsp;child\n"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$sockets</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]);<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
child PID: 1378
message from child
</pre></div>
    </div>
   </div>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites