<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.eventhttp.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'eventhttp.bind.php',
    1 => 'EventHttp::bind',
    2 => 'Binds an HTTP server on the specified address and port',
  ),
  'up' => 
  array (
    0 => 'class.eventhttp.php',
    1 => 'EventHttp',
  ),
  'prev' => 
  array (
    0 => 'eventhttp.addserveralias.php',
    1 => 'EventHttp::addServerAlias',
  ),
  'next' => 
  array (
    0 => 'eventhttp.construct.php',
    1 => 'EventHttp::__construct',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/event/eventhttp/bind.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="eventhttp.bind" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">EventHttp::bind</h1>
  <p class="verinfo">(PECL event &gt;= 1.2.6-beta)</p><p class="refpurpose"><span class="refname">EventHttp::bind</span> &mdash; <span class="dc-title">Binds an HTTP server on the specified address and port</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-eventhttp.bind-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>EventHttp::bind</strong></span>(<span class="methodparam">
    
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$address</code>
   </span>, <span class="methodparam">
    
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$port</code>
   </span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   Binds an HTTP server on the specified address and port.
  </p>
  <p class="para">
   Can be called multiple times to bind the same HTTP server to multiple
   different ports.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-eventhttp.bind-parameters">
  <h3 class="title">Parameters</h3>
  <dl>
   
    <dt>
     <code class="parameter">address</code>
    </dt>
    <dd>
     <p class="para">
      A string containing the IP address to
      <code class="literal">listen(2)</code>
      on.
     </p>
    </dd>
   
   
    <dt>
     <code class="parameter">port</code>
    </dt>
    <dd>
     <p class="para">
      The port number to listen on.
     </p>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-eventhttp.bind-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success or <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> on failure.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-eventhttp.bind-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1">
   <p><strong>Example #1 
    <span class="function"><strong>EventHttp::bind()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$base </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventBase</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$http </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventHttp</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$socket </span><span style="color: #007700">= </span><span style="color: #0000BB">socket_create</span><span style="color: #007700">(</span><span style="color: #0000BB">AF_INET</span><span style="color: #007700">, </span><span style="color: #0000BB">SOCK_STREAM</span><span style="color: #007700">, </span><span style="color: #0000BB">SOL_TCP</span><span style="color: #007700">);<br /><br />if (!</span><span style="color: #0000BB">$http</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bind</span><span style="color: #007700">(</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">, </span><span style="color: #0000BB">8088</span><span style="color: #007700">)) {<br />    exit(</span><span style="color: #DD0000">"bind(1) failed\n"</span><span style="color: #007700">);<br />};<br />if (!</span><span style="color: #0000BB">$http</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">bind</span><span style="color: #007700">(</span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">, </span><span style="color: #0000BB">8089</span><span style="color: #007700">)) {<br />    exit(</span><span style="color: #DD0000">"bind(2) failed\n"</span><span style="color: #007700">);<br />};<br /><br /></span><span style="color: #0000BB">$http</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setCallback</span><span style="color: #007700">(</span><span style="color: #DD0000">"/about"</span><span style="color: #007700">, function(</span><span style="color: #0000BB">$req</span><span style="color: #007700">) {<br />    echo </span><span style="color: #DD0000">"URI: "</span><span style="color: #007700">, </span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getUri</span><span style="color: #007700">(), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />    </span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">sendReply</span><span style="color: #007700">(</span><span style="color: #0000BB">200</span><span style="color: #007700">, </span><span style="color: #DD0000">"OK"</span><span style="color: #007700">);<br />    echo </span><span style="color: #DD0000">"OK\n"</span><span style="color: #007700">;<br />});<br /><br /></span><span style="color: #0000BB">$base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">dispatch</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>The above example will output
something similar to:</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Client:

$ nc 127.0.0.1 8088
GET /about HTTP/1.0
Connection: close

HTTP/1.0 200 OK
Content-Type: text/html; charset=ISO-8859-1
Connection: close

$ nc 127.0.0.1 8089
GET /unknown HTTP/1.0
Connection: close

HTTP/1.1 404 Not Found
Content-Type: text/html
Date: Wed, 13 Mar 2013 04:14:41 GMT
Content-Length: 149
Connection: close

&lt;html&gt;&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Not Found&lt;/h1&gt;&lt;p&gt;The requested URL /unknown was not found on this server.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;

Server:
URI: /about
OK</pre>
</div>
   </div>
  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-eventhttp.bind-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li>
    <span class="methodname"><a href="eventhttp.accept.php" class="methodname" rel="rdfs-seeAlso">EventHttp::accept()</a> - Makes an HTTP server accept connections on the specified socket stream or resource</span>
   </li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>