<!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>Initiates 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-cmsg-space.html">socket_cmsg_space</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-create-listen.html">socket_create_listen</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-connect" class="refentry"> <div class="refnamediv"> <h1 class="refname">socket_connect</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5)</p><p class="refpurpose"><span class="refname">socket_connect</span> — <span class="dc-title">Initiates a connection on a socket</span></p> </div> <div class="refsect1 description" id="refsect1-function.socket-connect-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>socket_connect</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$address</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code><span class="initializer"> = 0</span></span> ] )</div> <p class="para rdfs-comment"> Initiate a connection to <em><code class="parameter">address</code></em> using the socket resource <em><code class="parameter">socket</code></em>, which must be a valid socket resource created with <span class="function"><a href="function.socket-create.html" class="function">socket_create()</a></span>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.socket-connect-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"> </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">address</code></em></span> <dd> <p class="para"> The <em><code class="parameter">address</code></em> parameter is either an IPv4 address in dotted-quad notation (e.g. <em>127.0.0.1</em>) if <em><code class="parameter">socket</code></em> is <strong><code>AF_INET</code></strong>, a valid IPv6 address (e.g. <em>::1</em>) if IPv6 support is enabled and <em><code class="parameter">socket</code></em> is <strong><code>AF_INET6</code></strong> or the pathname of a Unix domain socket, if the socket family is <strong><code>AF_UNIX</code></strong>. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">port</code></em></span> <dd> <p class="para"> The <em><code class="parameter">port</code></em> parameter is only used and is mandatory when connecting to an <strong><code>AF_INET</code></strong> or an <strong><code>AF_INET6</code></strong> socket, and designates the port on the remote host to which a connection should be made. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.socket-connect-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> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> If the socket is non-blocking then this function returns <strong><code>FALSE</code></strong> with an error <em>Operation now in progress</em>. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.socket-connect-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <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-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-last-error.html" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - Returns the last error on the 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="function.socket-cmsg-space.html">socket_cmsg_space</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-create-listen.html">socket_create_listen</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>