uTools-Manuals/docs/php/socket_write.html
2019-04-28 19:00:34 +08:00

130 lines
5.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>Write to a socket</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.socket-write" class="refentry">
<div class="refnamediv">
<h1 class="refname">socket_write</h1>
<p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</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" id="refsect1-function.socket-write-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>socket_write</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
, <span class="methodparam"><span class="type">string</span> <code class="parameter">$buffer</code></span>
[, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = 0</span></span>
] ) : <span class="type">int</span></div>
<p class="para rdfs-comment">
The function <span class="function"><strong>socket_write()</strong></span> writes to the
<code class="parameter">socket</code> from the given
<code class="parameter">buffer</code>.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.socket-write-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">socket</code></dt>
<dd>
<p class="para">
</p>
</dd>
<dt>
<code class="parameter">buffer</code></dt>
<dd>
<p class="para">
The buffer to be written.
</p>
</dd>
<dt>
<code class="parameter">length</code></dt>
<dd>
<p class="para">
The optional parameter <code class="parameter">length</code> can specify an
alternate length of bytes written to the socket. If this length is
greater than the buffer length, it is silently truncated to the length
of the buffer.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.socket-write-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
Returns the number of bytes successfully written to the socket 或者在失败时返回 <strong><code>FALSE</code></strong>.
The error code can be retrieved with
<span class="function"><a href="socket_last_error.html" class="function">socket_last_error()</a></span>. This code may be passed to
<span class="function"><a href="socket_strerror.html" class="function">socket_strerror()</a></span> to get a textual explanation of the
error.
</p>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
It is perfectly valid for <span class="function"><strong>socket_write()</strong></span> to
return zero which means no bytes have been written. Be sure to use the
<em>===</em> operator to check for <strong><code>FALSE</code></strong> in case of an
error.
</p>
</p></blockquote>
</div>
<div class="refsect1 notes" id="refsect1-function.socket-write-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>:
<p class="para">
<span class="function"><strong>socket_write()</strong></span> 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.
</p>
</p></blockquote>
</div>
<div class="refsect1 seealso" id="refsect1-function.socket-write-seealso">
<h3 class="title">参见</h3>
<p class="para">
<ul class="simplelist">
<li class="member"><span class="function"><a href="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="socket_bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - 给套接字绑定名字</span></li>
<li class="member"><span class="function"><a href="socket_connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - 开启一个套接字连接</span></li>
<li class="member"><span class="function"><a href="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="socket_read.html" class="function" rel="rdfs-seeAlso">socket_read()</a> - Reads a maximum of length bytes from a socket</span></li>
<li class="member"><span class="function"><a href="socket_strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
</ul>
</p>
</div>
</div></div></div></body></html>