<!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>Accepts 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="ref.sockets.html">Socket Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-bind.html">socket_bind</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-accept" class="refentry"> <div class="refnamediv"> <h1 class="refname">socket_accept</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">socket_accept</span> — <span class="dc-title">Accepts a connection on a socket</span></p> </div> <div class="refsect1 description" id="refsect1-function.socket-accept-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>socket_accept</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></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>, bound to a name with <span class="function"><a href="function.socket-bind.html" class="function">socket_bind()</a></span>, and told to listen for connections with <span class="function"><a href="function.socket-listen.html" class="function">socket_listen()</a></span>, this function will accept incoming connections on that socket. Once a successful connection is made, a new socket resource is returned, which may be used for communication. If there are multiple connections queued on the socket, the first will be used. If there are no pending connections, <span class="function"><strong>socket_accept()</strong></span> will block until a connection becomes present. If <em><code class="parameter">socket</code></em> has been made non-blocking using <span class="function"><a href="function.socket-set-blocking.html" class="function">socket_set_blocking()</a></span> or <span class="function"><a href="function.socket-set-nonblock.html" class="function">socket_set_nonblock()</a></span>, <strong><code>FALSE</code></strong> will be returned. </p> <p class="para"> The socket resource returned by <span class="function"><strong>socket_accept()</strong></span> may not be used to accept new connections. The original listening socket <em><code class="parameter">socket</code></em>, however, remains open and may be reused. </p> </div> <div class="refsect1 parameters" id="refsect1-function.socket-accept-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> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.socket-accept-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a new socket resource on success, or <strong><code>FALSE</code></strong> on error. The actual error code can be retrieved by calling <span class="function"><a href="function.socket-last-error.html" class="function">socket_last_error()</a></span>. This error 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-accept-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <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-listen.html" class="function" rel="rdfs-seeAlso">socket_listen()</a> - Listens for 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-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-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="ref.sockets.html">Socket Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-bind.html">socket_bind</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>