<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >socket_strerror</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="Socket Functions" HREF="ref.sockets.html"><LINK REL="PREVIOUS" TITLE="socket_shutdown" HREF="function.socket-shutdown.html"><LINK REL="NEXT" TITLE="socket_write" HREF="function.socket-write.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.socket-shutdown.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.socket-write.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.socket-strerror" ></A >socket_strerror</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN213851" ></A ><P > (PHP 4 >= 4.1.0, PHP 5)</P >socket_strerror -- Return a string describing a socket error</DIV ><DIV CLASS="refsect1" ><A NAME="AEN213854" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >socket_strerror</B > ( int errno )<BR ></BR ><P > <B CLASS="function" >socket_strerror()</B > takes as its <CODE CLASS="parameter" >errno</CODE > parameter a socket error code as returned by <A HREF="function.socket-last-error.html" ><B CLASS="function" >socket_last_error()</B ></A > and returns the corresponding explanatory text. This makes it a bit more pleasant to figure out why something didn't work; for instance, instead of having to track down a system include file to find out what '-111' means, you just pass it to <B CLASS="function" >socket_strerror()</B >, and it tells you what happened. </P ><P > <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN213868" ></A ><P ><B >例 1. <B CLASS="function" >socket_strerror()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#007700">if (</font><font color="#0000BB">false </font><font color="#007700">== (</font><font color="#0000BB">$socket </font><font color="#007700">= @</font><font color="#0000BB">socket_create</font><font color="#007700">(</font><font color="#0000BB">AF_INET</font><font color="#007700">, </font><font color="#0000BB">SOCK_STREAM</font><font color="#007700">, </font><font color="#0000BB">SOL_TCP</font><font color="#007700">))) {<br /> echo </font><font color="#DD0000">"socket_create() failed: reason: " </font><font color="#007700">. </font><font color="#0000BB">socket_strerror</font><font color="#007700">(</font><font color="#0000BB">socket_last_error</font><font color="#007700">()) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />} <br /><br />if (</font><font color="#0000BB">false </font><font color="#007700">== (@</font><font color="#0000BB">socket_bind</font><font color="#007700">(</font><font color="#0000BB">$socket</font><font color="#007700">, </font><font color="#DD0000">'127.0.0.1'</font><font color="#007700">, </font><font color="#0000BB">80</font><font color="#007700">))) {<br /> echo </font><font color="#DD0000">"socket_bind() failed: reason: " </font><font color="#007700">. </font><font color="#0000BB">socket_strerror</font><font color="#007700">(</font><font color="#0000BB">socket_last_error</font><font color="#007700">(</font><font color="#0000BB">$socket</font><font color="#007700">)) . </font><font color="#DD0000">"\n"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P > The expected output from the above example (assuming the script is not run with root privileges): </P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >socket_bind() failed: reason: Permission denied</PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > See also <A HREF="function.socket-accept.html" ><B CLASS="function" >socket_accept()</B ></A >, <A HREF="function.socket-bind.html" ><B CLASS="function" >socket_bind()</B ></A >, <A HREF="function.socket-connect.html" ><B CLASS="function" >socket_connect()</B ></A >, <A HREF="function.socket-listen.html" ><B CLASS="function" >socket_listen()</B ></A >, and <A HREF="function.socket-create.html" ><B CLASS="function" >socket_create()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.socket-shutdown.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.socket-write.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >socket_shutdown</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sockets.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >socket_write</TD ></TR ></TABLE ></DIV ></BODY ></HTML >