<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.eventhttpconnection.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'ja',
  ),
  'this' => 
  array (
    0 => 'eventhttpconnection.makerequest.php',
    1 => 'EventHttpConnection::makeRequest',
    2 => 'Makes an HTTP request over the specified connection',
  ),
  'up' => 
  array (
    0 => 'class.eventhttpconnection.php',
    1 => 'EventHttpConnection',
  ),
  'prev' => 
  array (
    0 => 'eventhttpconnection.getpeer.php',
    1 => 'EventHttpConnection::getPeer',
  ),
  'next' => 
  array (
    0 => 'eventhttpconnection.setclosecallback.php',
    1 => 'EventHttpConnection::setCloseCallback',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/event/eventhttpconnection/makerequest.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="eventhttpconnection.makerequest" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">EventHttpConnection::makeRequest</h1>
  <p class="verinfo">(PECL event &gt;= 1.4.0-beta)</p><p class="refpurpose"><span class="refname">EventHttpConnection::makeRequest</span> &mdash; <span class="dc-title">Makes an HTTP request over the specified connection</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-eventhttpconnection.makerequest-description">
  <h3 class="title">説明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span>
   <span class="methodname"><strong>EventHttpConnection::makeRequest</strong></span>(<span class="methodparam">
    
    <span class="type"><a href="class.eventhttprequest.php" class="type EventHttpRequest">EventHttpRequest</a></span> <code class="parameter">$req</code>
   </span>, <span class="methodparam">
    
    <span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$type</code>
   </span>, <span class="methodparam">
    
    <span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$uri</code>
   </span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Makes an HTTP request over the specified connection.
   <code class="parameter">type</code>
   is one of
   <code class="literal">EventHttpRequest::CMD_*</code>
   constants.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-eventhttpconnection.makerequest-parameters">
  <h3 class="title">パラメータ</h3>
  <dl>
   
    <dt>
     <code class="parameter">req</code>
    </dt>
    <dd>
     <p class="para">
      The connection object over which to send the request.
     </p>
    </dd>
   
   
    <dt>
     <code class="parameter">type</code>
    </dt>
    <dd>
     <p class="para">
      One of
      <a href="class.eventhttprequest.php#eventhttprequest.constants" class="link">
       <code class="literal">EventHttpRequest::CMD_*</code> constants</a>.
     </p>
    </dd>
   
   
    <dt>
     <code class="parameter">uri</code>
    </dt>
    <dd>
     <p class="para">
      The URI associated with the request.
     </p>
    </dd>
   
  </dl>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-eventhttpconnection.makerequest-returnvalues">
  <h3 class="title">戻り値</h3>
  <p class="para">
   成功した場合に <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> を、失敗した場合に <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> を返します。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-eventhttpconnection.makerequest-examples">
  <h3 class="title">例</h3>
  <div class="example" id="example-1">
   <p><strong>例1 
    <span class="function"><strong>EventHttpConnection::makeRequest()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">_request_handler</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">, </span><span style="color: #0000BB">$base</span><span style="color: #007700">) {<br />    echo </span><span style="color: #0000BB">__FUNCTION__</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />    if (</span><span style="color: #0000BB">is_null</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">)) {<br />        echo </span><span style="color: #DD0000">"Timed out\n"</span><span style="color: #007700">;<br />    } else {<br />        </span><span style="color: #0000BB">$response_code </span><span style="color: #007700">= </span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getResponseCode</span><span style="color: #007700">();<br /><br />        if (</span><span style="color: #0000BB">$response_code </span><span style="color: #007700">== </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"Connection refused\n"</span><span style="color: #007700">;<br />        } elseif (</span><span style="color: #0000BB">$response_code </span><span style="color: #007700">!= </span><span style="color: #0000BB">200</span><span style="color: #007700">) {<br />            echo </span><span style="color: #DD0000">"Unexpected response: </span><span style="color: #0000BB">$response_code</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />        } else {<br />            echo </span><span style="color: #DD0000">"Success: </span><span style="color: #0000BB">$response_code</span><span style="color: #DD0000">\n"</span><span style="color: #007700">;<br />            </span><span style="color: #0000BB">$buf </span><span style="color: #007700">= </span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getInputBuffer</span><span style="color: #007700">();<br />            echo </span><span style="color: #DD0000">"Body:\n"</span><span style="color: #007700">;<br />            while (</span><span style="color: #0000BB">$s </span><span style="color: #007700">= </span><span style="color: #0000BB">$buf</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">readLine</span><span style="color: #007700">(</span><span style="color: #0000BB">EventBuffer</span><span style="color: #007700">::</span><span style="color: #0000BB">EOL_ANY</span><span style="color: #007700">)) {<br />                echo </span><span style="color: #0000BB">$s</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />            }<br />        }<br />    }<br /><br />    </span><span style="color: #0000BB">$base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exit</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$address </span><span style="color: #007700">= </span><span style="color: #DD0000">"127.0.0.1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$port </span><span style="color: #007700">= </span><span style="color: #0000BB">80</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$base </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventBase</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$conn </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventHttpConnection</span><span style="color: #007700">(</span><span style="color: #0000BB">$base</span><span style="color: #007700">, </span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #0000BB">$address</span><span style="color: #007700">, </span><span style="color: #0000BB">$port</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeout</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$req </span><span style="color: #007700">= new </span><span style="color: #0000BB">EventHttpRequest</span><span style="color: #007700">(</span><span style="color: #DD0000">"_request_handler"</span><span style="color: #007700">, </span><span style="color: #0000BB">$base</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addHeader</span><span style="color: #007700">(</span><span style="color: #DD0000">"Host"</span><span style="color: #007700">, </span><span style="color: #0000BB">$address</span><span style="color: #007700">, </span><span style="color: #0000BB">EventHttpRequest</span><span style="color: #007700">::</span><span style="color: #0000BB">OUTPUT_HEADER</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$req</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">addHeader</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Length"</span><span style="color: #007700">, </span><span style="color: #DD0000">"0"</span><span style="color: #007700">, </span><span style="color: #0000BB">EventHttpRequest</span><span style="color: #007700">::</span><span style="color: #0000BB">OUTPUT_HEADER</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">makeRequest</span><span style="color: #007700">(</span><span style="color: #0000BB">$req</span><span style="color: #007700">, </span><span style="color: #0000BB">EventHttpRequest</span><span style="color: #007700">::</span><span style="color: #0000BB">CMD_GET</span><span style="color: #007700">, </span><span style="color: #DD0000">"/index.cphp"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$base</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
   </div>

   <div class="example-contents"><p>上の例の出力は、
たとえば以下のようになります。</p></div>
   <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">_request_handler
Success: 200
Body:
PHP, date:
2013-03-13T20:27:52+05:00</pre>
</div>
   </div>
  </div>
 </div>

 <div class="refsect1 seealso" id="refsect1-eventhttpconnection.makerequest-seealso">
  <h3 class="title">参考</h3>
  <ul class="simplelist">
   <li>
    <span class="methodname"><a href="eventhttprequest.addheader.php" class="methodname" rel="rdfs-seeAlso">EventHttpRequest::addHeader()</a> - Adds an HTTP header to the headers of the request</span>
   </li>
  </ul>
 </div>

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