<HTML ><HEAD ><TITLE >socket_read</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_listen" HREF="function.socket-listen.html"><LINK REL="NEXT" TITLE="socket_readv" HREF="function.socket-readv.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-listen.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-readv.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.socket-read" ></A >socket_read</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN87700" ></A ><P > (PHP 4 >= 4.1.0)</P >socket_read -- Reads a maximum of length bytes from a socket</DIV ><DIV CLASS="refsect1" ><A NAME="AEN87703" ></A ><H2 >Description</H2 >string <B CLASS="methodname" >socket_read</B > ( resource socket, int length [, int type])<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 > The function <B CLASS="function" >socket_read()</B > reads from the socket resource <TT CLASS="parameter" ><I >socket</I ></TT > created by the <A HREF="function.socket-create.html" ><B CLASS="function" >socket_create()</B ></A > or <A HREF="function.socket-accept.html" ><B CLASS="function" >socket_accept()</B ></A > functions. The maximum number of bytes read is specified by the <TT CLASS="parameter" ><I >length</I ></TT > parameter. Otherwise you can use \r, \n, or \0 to end reading (depending on the <TT CLASS="parameter" ><I >type</I ></TT > parameter, see below). </P ><P > <B CLASS="function" >socket_read()</B > returns the data as a string on success, or <TT CLASS="constant" ><B >FALSE</B ></TT > on error. The error code can be retrieved with <A HREF="function.socket-last-error.html" ><B CLASS="function" >socket_last_error()</B ></A >. This code may be passed to <A HREF="function.socket-strerror.html" ><B CLASS="function" >socket_strerror()</B ></A > to get a textual representation of the error. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Note: </B > <B CLASS="function" >socket_read()</B > may return a zero length string ("") indicating the end of communication (i.e. the remote end point has closed the connection). </P ></BLOCKQUOTE ></DIV ><P > Optional <TT CLASS="parameter" ><I >type</I ></TT > parameter is a named constant: <P ></P ><UL ><LI ><P > PHP_BINARY_READ - use the system <TT CLASS="literal" >read()</TT > function. Safe for reading binary data. (Default in PHP >= 4.1.0) </P ></LI ><LI ><P > PHP_NORMAL_READ - reading stops at \n or \r. (Default in PHP <= 4.0.6) </P ></LI ></UL > </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 >, <A HREF="function.socket-last-error.html" ><B CLASS="function" >socket_last_error()</B ></A >, <A HREF="function.socket-strerror.html" ><B CLASS="function" >socket_strerror()</B ></A > and <A HREF="function.socket-write.html" ><B CLASS="function" >socket_write()</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-listen.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-readv.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >socket_listen</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_readv</TD ></TR ></TABLE ></DIV ></BODY ></HTML >