<HTML ><HEAD ><TITLE >socket_last_error</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REL="HOME" TITLE="PHP Manual" HREF="index.html"><LINK REL="UP" TITLE="Socket functions" HREF="ref.sockets.html"><LINK REL="PREVIOUS" TITLE="socket_iovec_set" HREF="function.socket-iovec-set.html"><LINK REL="NEXT" TITLE="socket_listen" HREF="function.socket-listen.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=ISO-8859-1"></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 Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.socket-iovec-set.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.socket-listen.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.socket-last-error" ></A >socket_last_error</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN87628" ></A ><P > (PHP 4 >= 4.1.0)</P >socket_last_error -- Returns the last error on the socket </DIV ><DIV CLASS="refsect1" ><A NAME="AEN87631" ></A ><H2 >Description</H2 >int <B CLASS="methodname" >socket_last_error</B > ( [resource socket])<BR ></BR ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >Warning</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P >This function is <SPAN CLASS="emphasis" ><I CLASS="emphasis" >EXPERIMENTAL</I ></SPAN >. The behaviour of this function, the name of this function, and anything else documented about this function may change without notice in a future release of PHP. Use this function at your own risk.</P ></TD ></TR ></TABLE ></DIV ><P > This function returns a socket error code. </P ><P > If a socket resource is passed to this function, the last error which occured on this particular socket is returned. If the socket resource is ommited, the error code of the last failed socket function is returned. The latter is in particular helpful for functions like <A HREF="function.socket-create.html" ><B CLASS="function" >socket_create()</B ></A > which don't return a socket on failure and <A HREF="function.socket-select.html" ><B CLASS="function" >socket_select()</B ></A > which can fail for reasons not directly tied to a particular socket. The error code is suitable to be fed to <A HREF="function.socket-strerror.html" ><B CLASS="function" >socket_strerror()</B ></A > which returns a string describing the given error code. <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="php" >if (false == ($socket = @socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) { die("Couldn't create socket, error code is: " . socket_last_error() . ",error message is: " . socket_strerror(socket_last_error())); }</PRE ></TD ></TR ></TABLE > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > <B CLASS="function" >socket_last_error()</B > does not clear the error code, use <A HREF="function.socket-clear-error.html" ><B CLASS="function" >socket_clear_error()</B ></A > for this purpose. </P ></BLOCKQUOTE ></DIV ></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-iovec-set.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.socket-listen.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >socket_iovec_set</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sockets.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >socket_listen</TD ></TR ></TABLE ></DIV ></BODY ></HTML >