Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 6280

php-manual-en-7.2.11-1.mga7.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>Reads a maximum of length bytes from a socket</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.socket-listen.html">socket_listen</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-recv.html">socket_recv</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-read" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_read</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_read</span> &mdash; <span class="dc-title">Reads a maximum of length bytes from a socket</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-read-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>socket_read</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$type</code><span class="initializer"> = PHP_BINARY_READ</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   The function <span class="function"><strong>socket_read()</strong></span> reads from the socket
   resource <code class="parameter">socket</code> created by the
   <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span> or
   <span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span> functions. 
  </p>
 </div>


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

    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       A valid socket resource created with <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span>
       or <span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">length</code></dt>

     <dd>

      <p class="para">
       The maximum number of bytes read is specified by the
       <code class="parameter">length</code> parameter. Otherwise you can use
       <strong><code>\r</code></strong>, <strong><code>\n</code></strong>,
       or <strong><code>\0</code></strong> to end reading (depending on the <code class="parameter">type</code>
       parameter, see below).
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">type</code></dt>

     <dd>

      <p class="para">
       Optional <code class="parameter">type</code> parameter is a named constant:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          <strong><code>PHP_BINARY_READ</code></strong> (Default) - use the system
          <em>recv()</em> function. Safe for reading binary data.
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          <strong><code>PHP_NORMAL_READ</code></strong> - reading stops at
          <em>\n</em> or <em>\r</em>.
         </span>
        </li>
       </ul>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-read-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   <span class="function"><strong>socket_read()</strong></span> returns the data as a string on success,
   or <strong><code>FALSE</code></strong> on error (including if the remote host has closed the
   connection). The error code can be retrieved with
   <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span>. This code may be passed to
   <span class="function"><a href="function.socket-strerror.html" class="function">socket_strerror()</a></span> to get a textual representation of
   the error.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>socket_read()</strong></span> returns a zero length string (&quot;&quot;)
    when there is no more data to read.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-read-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>
    <li class="member"><span class="function"><a href="function.socket-write.html" class="function" rel="rdfs-seeAlso">socket_write()</a> - Write to a socket</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-listen.html">socket_listen</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.socket-recv.html">socket_recv</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>