function.socket-write.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 149 行

HTML
149 行
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Write to a socket</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.sockets.html">Socket Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.ssh2.html">SSH2</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-write" class="refentry"> <div class="refnamediv">  <h1 class="refname">socket_write</h1>  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5)</p><p class="refpurpose"><span class="refname">socket_write</span> &mdash; <span class="dc-title">Write to a socket</span></p> </div>  <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">int</span> <span class="methodname"><b><b>socket_write</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$socket</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$buffer</tt></span>   [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$length</tt></span>  ] )</div>  <p class="para rdfs-comment">   The function <b>socket_write()</b> writes to the   <i><tt class="parameter">socket</tt></i> from the given   <i><tt class="parameter">buffer</tt></i>.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">socket</tt></i></span>     <dd>      <p class="para">      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">buffer</tt></i></span>     <dd>      <p class="para">       The buffer to be written.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">length</tt></i></span>     <dd>      <p class="para">       The optional parameter <i><tt class="parameter">length</tt></i> can specify an       alternate length of bytes written to the socket. If this length is       greater then the buffer length, it is silently truncated to the length       of the buffer.      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns the number of bytes successfully written to the socket or <b><tt>FALSE</tt></b>   one error. The error code can be retrieved with   <a href="function.socket-last-error.html" class="function">socket_last_error()</a>. This code may be passed to   <a href="function.socket-strerror.html" class="function">socket_strerror()</a> to get a textual explanation of the   error.  </p>  <blockquote><p><b class="note">Note</b>:        It is perfectly valid for <b>socket_write()</b> to    return zero which means no bytes have been written. Be sure to use the    <i>===</i> operator to check for <b><tt>FALSE</tt></b> in case of an    error.   <br />  </p></blockquote> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>:        <b>socket_write()</b> does not necessarily write all bytes    from the given buffer. It&#039;s valid that, depending on the network    buffers etc., only a certain amount of data, even one byte, is written    though your buffer is greater. You have to watch out so you don&#039;t    unintentionally forget to transmit the rest of your data.   <br />  </p></blockquote> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.socket-accept.html" class="function" rel="rdfs-seeAlso">socket_accept()</a></li>    <li class="member"><a href="function.socket-bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a></li>    <li class="member"><a href="function.socket-connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a></li>    <li class="member"><a href="function.socket-listen.html" class="function" rel="rdfs-seeAlso">socket_listen()</a></li>    <li class="member"><a href="function.socket-read.html" class="function" rel="rdfs-seeAlso">socket_read()</a></li>    <li class="member"><a href="function.socket-strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.sockets.html">Socket Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.ssh2.html">SSH2</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>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?