<!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>Sets nonblocking mode for file descriptor fd</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.socket-set-block.html">socket_set_block</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-set-option.html">socket_set_option</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-set-nonblock" class="refentry"> <div class="refnamediv"> <h1 class="refname">socket_set_nonblock</h1> <p class="verinfo">(PHP 4 >= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_set_nonblock</span> — <span class="dc-title">Sets nonblocking mode for file descriptor fd </span></p> </div> <div class="refsect1 description" id="refsect1-function.socket-set-nonblock-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>socket_set_nonblock</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span> )</div> <p class="para rdfs-comment"> The <span class="function"><strong>socket_set_nonblock()</strong></span> function sets the <strong><code>O_NONBLOCK</code></strong> flag on the socket specified by the <code class="parameter">socket</code> parameter. </p> <p class="para"> When an operation (e.g. receive, send, connect, accept, ...) is performed on a non-blocking socket, the script will not pause its execution until it receives a signal or it can perform the operation. Rather, if the operation would result in a block, the called function will fail. </p> </div> <div class="refsect1 parameters" id="refsect1-function.socket-set-nonblock-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">socket</code></dt> <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> or <span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span>. </p> </dd> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.socket-set-nonblock-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. </p> </div> <div class="refsect1 examples" id="refsect1-function.socket-set-nonblock-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-5740"> <p><strong>Example #1 <span class="function"><strong>socket_set_nonblock()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$socket </span><span style="color: #007700">= </span><span style="color: #0000BB">socket_create_listen</span><span style="color: #007700">(</span><span style="color: #0000BB">1223</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">socket_set_nonblock</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">socket_accept</span><span style="color: #007700">(</span><span style="color: #0000BB">$socket</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p> This example creates a listening socket on all interfaces on port 1223 and sets the socket to <strong><code>O_NONBLOCK</code></strong> mode. <span class="function"><a href="function.socket-accept.html" class="function">socket_accept()</a></span> will immediately fail unless there is a pending connection exactly at this moment. </p></div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.socket-set-nonblock-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><span class="function"><a href="function.socket-set-block.html" class="function" rel="rdfs-seeAlso">socket_set_block()</a> - Sets blocking mode on a socket resource</span></li> <li class="member"><span class="function"><a href="function.socket-set-option.html" class="function" rel="rdfs-seeAlso">socket_set_option()</a> - Sets socket options for the socket</span></li> <li class="member"><span class="function"><a href="function.stream-set-blocking.html" class="function" rel="rdfs-seeAlso">stream_set_blocking()</a> - Set blocking/non-blocking mode on a stream</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-set-block.html">socket_set_block</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.socket-set-option.html">socket_set_option</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>