<!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>Listens for a connection on a socket</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-last-error.html">socket_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-read.html">socket_read</a></div> <div class="up"><a href="ref.sockets.html">Socket Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.socket-listen" class="refentry"> <div class="refnamediv"> <h1 class="refname">socket_listen</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">socket_listen</span> — <span class="dc-title">Listens for a connection on a socket</span></p> </div> <div class="refsect1 description" id="refsect1-function.socket-listen-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>socket_listen</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$backlog</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> After the socket <em><code class="parameter">socket</code></em> has been created using <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span> and bound to a name with <span class="function"><a href="function.socket-bind.html" class="function">socket_bind()</a></span>, it may be told to listen for incoming connections on <em><code class="parameter">socket</code></em>. </p> <p class="para"> <span class="function"><strong>socket_listen()</strong></span> is applicable only to sockets of type <strong><code>SOCK_STREAM</code></strong> or <strong><code>SOCK_SEQPACKET</code></strong>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.socket-listen-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">socket</code></em></span> <dd> <p class="para"> A valid socket resource created with <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">backlog</code></em></span> <dd> <p class="para"> A maximum of <em><code class="parameter">backlog</code></em> incoming connections will be queued for processing. If a connection request arrives with the queue full the client may receive an error with an indication of <em>ECONNREFUSED</em>, or, if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> The maximum number passed to the <em><code class="parameter">backlog</code></em> parameter highly depends on the underlying platform. On Linux, it is silently truncated to <strong><code>SOMAXCONN</code></strong>. On win32, if passed <strong><code>SOMAXCONN</code></strong>, the underlying service provider responsible for the socket will set the backlog to a maximum <em class="emphasis">reasonable</em> value. There is no standard provision to find out the actual backlog value on this platform. </p> </p></blockquote> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.socket-listen-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. The error code can be retrieved with <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span>. This code may be passed to <span class="function"><a href="function.socket-strerror.html" class="function">socket_strerror()</a></span> to get a textual explanation of the error. </p> </div> <div class="refsect1 seealso" id="refsect1-function.socket-listen-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.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="function.socket-bind.html" class="function" rel="rdfs-seeAlso">socket_bind()</a> - Binds a name to a socket</span></li> <li class="member"> <span class="function"><a href="function.socket-connect.html" class="function" rel="rdfs-seeAlso">socket_connect()</a> - Initiates a connection on a socket</span></li> <li class="member"> <span class="function"><a href="function.socket-create.html" class="function" rel="rdfs-seeAlso">socket_create()</a> - Create a socket (endpoint for communication)</span></li> <li class="member"> <span class="function"><a href="function.socket-strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-last-error.html">socket_last_error</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-read.html">socket_read</a></div> <div class="up"><a href="ref.sockets.html">Socket Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>