mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-17 21:16:57 +08:00
99 lines
5.2 KiB
HTML
99 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>Returns the last error on the socket</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><div id="function.socket-last-error" class="refentry">
|
|
<div class="refnamediv">
|
|
<h1 class="refname">socket_last_error</h1>
|
|
<p class="verinfo">(PHP 4 >= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_last_error</span> — <span class="dc-title">Returns the last error on the socket </span></p>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 description" id="refsect1-function.socket-last-error-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>socket_last_error</strong></span>
|
|
([ <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
|
|
] ) : <span class="type">int</span></div>
|
|
|
|
<p class="para rdfs-comment">
|
|
If a socket resource is passed to this function, the last error which
|
|
occurred on this particular socket is returned. If the socket resource is
|
|
omitted, the error code of the last failed socket function is returned.
|
|
The latter is particularly helpful for functions like
|
|
<span class="function"><a href="socket_create.html" class="function">socket_create()</a></span> which don't return a socket on
|
|
failure and <span class="function"><a href="socket_select.html" class="function">socket_select()</a></span> which can fail for reasons
|
|
not directly tied to a particular socket. The error code is suitable to
|
|
be fed to <span class="function"><a href="socket_strerror.html" class="function">socket_strerror()</a></span> which returns a string
|
|
describing the given error code.
|
|
</p>
|
|
<p class="para">
|
|
If no error had occurred, or the error had been cleared with
|
|
<span class="function"><a href="socket_clear_error.html" class="function">socket_clear_error()</a></span>, the function returns <em>0</em>.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.socket-last-error-parameters">
|
|
<h3 class="title">参数</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="socket_create.html" class="function">socket_create()</a></span>.
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.socket-last-error-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
This function returns a socket error code.
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 examples" id="refsect1-function.socket-last-error-examples">
|
|
<h3 class="title">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="snmp.set.example.basic">
|
|
<p><strong>Example #1 <span class="function"><strong>socket_last_error()</strong></span> example</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br />$socket </span><span style="color: #007700">= @</span><span style="color: #0000BB">socket_create</span><span style="color: #007700">(</span><span style="color: #0000BB">AF_INET</span><span style="color: #007700">, </span><span style="color: #0000BB">SOCK_STREAM</span><span style="color: #007700">, </span><span style="color: #0000BB">SOL_TCP</span><span style="color: #007700">);<br /><br />if (</span><span style="color: #0000BB">$socket </span><span style="color: #007700">=== </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">$errorcode </span><span style="color: #007700">= </span><span style="color: #0000BB">socket_last_error</span><span style="color: #007700">();<br /> </span><span style="color: #0000BB">$errormsg </span><span style="color: #007700">= </span><span style="color: #0000BB">socket_strerror</span><span style="color: #007700">(</span><span style="color: #0000BB">$errorcode</span><span style="color: #007700">);<br /> <br /> die(</span><span style="color: #DD0000">"Couldn't create socket: [</span><span style="color: #0000BB">$errorcode</span><span style="color: #DD0000">] </span><span style="color: #0000BB">$errormsg</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 notes" id="refsect1-function.socket-last-error-notes">
|
|
<h3 class="title">注释</h3>
|
|
<blockquote class="note"><p><strong class="note">Note</strong>:
|
|
<p class="para">
|
|
<span class="function"><strong>socket_last_error()</strong></span> does not clear the error code, use
|
|
<span class="function"><a href="socket_clear_error.html" class="function">socket_clear_error()</a></span> for this purpose.
|
|
</p>
|
|
</p></blockquote>
|
|
</div>
|
|
|
|
|
|
</div></div></div></body></html> |