Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5809

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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 a socket (endpoint for communication)</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.socket-create-pair.html">socket_create_pair</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-get-option.html">socket_get_option</a></div>
 <div class="up"><a href="ref.sockets.html">Socket Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.socket-create" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_create</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">socket_create</span> &mdash; <span class="dc-title">Create a socket (endpoint for communication)</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-create-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>socket_create</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$domain</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$protocol</code></span>
   )</div>

  <p class="para rdfs-comment">
   Creates and returns a socket resource, also referred to as an endpoint
   of communication. A typical network connection is made up of 2 sockets, one
   performing the role of the client, and another performing the role of the server.
  </p>
 </div>


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

    <dt>

     <span class="term"><em><code class="parameter">domain</code></em></span>
     <dd>

      <p class="para">
       The <em><code class="parameter">domain</code></em> parameter specifies the protocol
       family to be used by the socket.
      </p>
      <table class="doctable table">
       <caption><strong>Available address/protocol families</strong></caption>
       
        <thead>
         <tr>
          <th>Domain</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td><strong><code>AF_INET</code></strong></td>
          <td>
           IPv4 Internet based protocols. TCP and UDP are common protocols of
           this protocol family.
          </td>
         </tr>

         <tr>
          <td><strong><code>AF_INET6</code></strong></td>
          <td>
           IPv6 Internet based protocols. TCP and UDP are common protocols of
           this protocol family.
          </td>
         </tr>

         <tr>
          <td><strong><code>AF_UNIX</code></strong></td>
          <td>
           Local communication protocol family. High efficiency and low
           overhead make it a great form of IPC (Interprocess Communication).
          </td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">type</code></em></span>
     <dd>

      <p class="para">
       The <em><code class="parameter">type</code></em> parameter selects the type of communication
       to be used by the socket.
      </p>
      <table class="doctable table">
       <caption><strong>Available socket types</strong></caption>
       
        <thead>
         <tr>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td><strong><code>SOCK_STREAM</code></strong></td>
          <td>
           Provides sequenced, reliable, full-duplex, connection-based byte streams.
           An out-of-band data transmission mechanism may be supported.
           The TCP protocol is based on this socket type.
          </td>
         </tr>

         <tr>
          <td><strong><code>SOCK_DGRAM</code></strong></td>
          <td>
           Supports datagrams (connectionless, unreliable messages of a fixed maximum length).
           The UDP protocol is based on this socket type.
          </td>
         </tr>

           <tr>
          <td><strong><code>SOCK_SEQPACKET</code></strong></td>
          <td>
           Provides a sequenced, reliable, two-way connection-based data transmission path for
           datagrams of fixed maximum length;  a consumer is required to read an
           entire packet with each read call.
          </td>
         </tr>

         <tr>
          <td><strong><code>SOCK_RAW</code></strong></td>
          <td>
           Provides raw network protocol access. This special type of socket
           can be used to manually construct any type of protocol. A common use
           for this socket type is to perform ICMP requests (like ping).
          </td>
         </tr>

         <tr>
          <td><strong><code>SOCK_RDM</code></strong></td>
          <td>
           Provides a reliable datagram layer that does not guarantee ordering.
           This is most likely not implemented on your operating system.
          </td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">protocol</code></em></span>
     <dd>

      <p class="para">
       The <em><code class="parameter">protocol</code></em> parameter sets the specific
       protocol within the specified <em><code class="parameter">domain</code></em> to be used
       when communicating on the returned socket. The proper value can be
       retrieved by name by using  <span class="function"><a href="function.getprotobyname.html" class="function">getprotobyname()</a></span>. If
       the desired protocol is TCP, or UDP the corresponding constants
       <strong><code>SOL_TCP</code></strong>, and <strong><code>SOL_UDP</code></strong>
       can also be used.
      </p>
      <table class="doctable table">
       <caption><strong>Common protocols</strong></caption>
       
        <thead>
         <tr>
          <th>Name</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         <tr>
          <td>icmp</td>
          <td>
           The Internet Control Message Protocol is used primarily by gateways
           and hosts to report errors in datagram communication. The &quot;ping&quot;
           command (present in most modern operating systems) is an example
           application of ICMP.
          </td>
         </tr>

         <tr>
          <td>udp</td>
          <td>
           The User Datagram Protocol is a connectionless, unreliable,
           protocol with fixed record lengths. Due to these aspects, UDP
           requires a minimum amount of protocol overhead.
          </td>
         </tr>

         <tr>
          <td>tcp</td>
          <td>
           The Transmission Control Protocol is a reliable, connection based,
           stream oriented, full duplex protocol. TCP guarantees that all data packets
           will be received in the order in which they were sent. If any packet is somehow
           lost during communication, TCP will automatically retransmit the packet until
           the destination host acknowledges that packet. For reliability and performance
           reasons, the TCP implementation itself decides the appropriate octet boundaries
           of the underlying datagram communication layer. Therefore, TCP applications must
           allow for the possibility of partial record transmission.
          </td>
         </tr>

        </tbody>
       
      </table>

     </dd>

    </dt>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-create-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
    <span class="function"><strong>socket_create()</strong></span> returns a socket resource on success,
   or <strong><code>FALSE</code></strong> on error. The actual error code can be retrieved by calling
    <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span>. This error code may be passed to
    <span class="function"><a href="function.socket-strerror.html" class="function">socket_strerror()</a></span> to get a textual explanation of the
   error.
  </p>
 </div>


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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.0.0</td>
       <td>
        The <strong><code>AF_INET6</code></strong> constant was added.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.socket-create-errors">
  <h3 class="title">Errors/Exceptions</h3>
   <p class="para">
    If an invalid <em><code class="parameter">domain</code></em> or
    <em><code class="parameter">type</code></em> is given,  <span class="function"><strong>socket_create()</strong></span>
    defaults to <strong><code>AF_INET</code></strong> and
    <strong><code>SOCK_STREAM</code></strong> respectively and additionally emits an
    <strong><code>E_WARNING</code></strong> message.
   </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-create-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.socket-accept.html" class="function" rel="rdfs-seeAlso">socket_accept()</a> - Accepts a connection on a socket</span></li>
    <li class="member"> <span class="function"><a href="function.socket-bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - Binds a name to a socket</span></li>
    <li class="member"> <span class="function"><a href="function.socket-connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - Initiates a connection on a socket</span></li>
    <li class="member"> <span class="function"><a href="function.socket-listen.html" class="function" rel="rdfs-seeAlso">socket_listen()</a> - Listens for a connection on a socket</span></li>
    <li class="member"> <span class="function"><a href="function.socket-last-error.html" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - Returns the last error on the socket</span></li>
    <li class="member"> <span class="function"><a href="function.socket-strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.socket-create-pair.html">socket_create_pair</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-get-option.html">socket_get_option</a></div>
 <div class="up"><a href="ref.sockets.html">Socket Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>