mirror of
https://github.com/php/doc-pt_br.git
synced 2026-03-24 07:02:09 +01:00
250 lines
6.1 KiB
XML
250 lines
6.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: a47dff201e3f65c07f6c84a535951632771cf72d Maintainer: leonardolara Status: ready --><!-- CREDITS: leonardolara -->
|
|
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="eventhttp.construct">
|
|
<refnamediv>
|
|
<refname>EventHttp::__construct</refname>
|
|
<refpurpose>Constrói objeto EventHttp (o servidor HTTP)</refpurpose>
|
|
</refnamediv>
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier>
|
|
<methodname>EventHttp::__construct</methodname>
|
|
<methodparam>
|
|
<type>EventBase</type>
|
|
<parameter>base</parameter>
|
|
</methodparam>
|
|
<methodparam choice="opt">
|
|
<type>EventSslContext</type>
|
|
<parameter>ctx</parameter>
|
|
<initializer>&null;</initializer>
|
|
</methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Constrói o objeto do servidor HTTP.
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>base</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Base de eventos associada.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term>
|
|
<parameter>ctx</parameter>
|
|
</term>
|
|
<listitem>
|
|
<para>
|
|
Objeto da classe <classname>EventSslContext</classname>.
|
|
Transforma servidor HTTP simples em servidor HTTPS. Isso significa que
|
|
se
|
|
<parameter>ctx</parameter>
|
|
estiver configurado corretamente, os eventos de buffer subjacentes serão baseados
|
|
em soquetes OpenSSL. Assim, todo o tráfego passará pelo SSL ou TLS.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Este parâmetro está disponível somente se
|
|
<literal>Event</literal>
|
|
for compilado com suporte OpenSSL e somente com
|
|
<literal>Libevent
|
|
2.1.0-alpha</literal>
|
|
e superior.
|
|
</para>
|
|
</note>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>PECL event 1.9.0</entry>
|
|
<entry>
|
|
Suporte OpenSSL (<parameter>ctx</parameter>) adicionado.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Servidor HTTP simples</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
/*
|
|
* Servidor HTTP simples.
|
|
*
|
|
* Para testar:
|
|
* 1) Execute-o em uma porta de sua escolha, por exemplo:
|
|
* $ php examples/http.php 8010
|
|
* 2) Em outro terminal, conecte-se a algum endereço nesta porta
|
|
* e faça uma solicitação GET ou POST (outras são desativadas aqui), por exemplo:
|
|
* $ nc -t 127.0.0.1 8010
|
|
* POST /about HTTP/1.0
|
|
* Content-Type: text/plain
|
|
* Content-Length: 4
|
|
* Connection: close
|
|
* (pressione Enter)
|
|
*
|
|
* Resultado:
|
|
* a=12
|
|
* HTTP/1.0 200 OK
|
|
* Content-Type: text/html; charset=ISO-8859-1
|
|
* Connection: close
|
|
*
|
|
* $ nc -t 127.0.0.1 8010
|
|
* GET /dump HTTP/1.0
|
|
* Content-Type: text/plain
|
|
* Content-Encoding: UTF-8
|
|
* Connection: close
|
|
* (pressione Enter)
|
|
*
|
|
* Resultado:
|
|
* HTTP/1.0 200 OK
|
|
* Content-Type: text/html; charset=ISO-8859-1
|
|
* Connection: close
|
|
* (pressione Enter)
|
|
*
|
|
* $ nc -t 127.0.0.1 8010
|
|
* GET /unknown HTTP/1.0
|
|
* Connection: close
|
|
*
|
|
* Resultado:
|
|
* HTTP/1.0 200 OK
|
|
* Content-Type: text/html; charset=ISO-8859-1
|
|
* Connection: close
|
|
*
|
|
* 3) Veja o que o servidor exibe na janela do terminal anterior.
|
|
*/
|
|
|
|
function _http_dump($req, $data) {
|
|
static $counter = 0;
|
|
static $max_requests = 2;
|
|
|
|
if (++$counter >= $max_requests) {
|
|
echo "O contador atingiu o máximo de solicitações $max_requests. Saindo\n";
|
|
exit();
|
|
}
|
|
|
|
echo __METHOD__, " chamado\n";
|
|
echo "requisição:"; var_dump($req);
|
|
echo "dados:"; var_dump($data);
|
|
|
|
echo "\n===== DUMP =====\n";
|
|
echo "Comando:", $req->getCommand(), PHP_EOL;
|
|
echo "URI:", $req->getUri(), PHP_EOL;
|
|
echo "Cabeçalhos de entrada:"; var_dump($req->getInputHeaders());
|
|
echo "Cabeçalhos de saída:"; var_dump($req->getOutputHeaders());
|
|
|
|
echo "\n >> Enviando resposta ...";
|
|
$req->sendReply(200, "OK");
|
|
echo "OK\n";
|
|
|
|
echo "\n >> Lendo buffer de entrada ...\n";
|
|
$buf = $req->getInputBuffer();
|
|
while ($s = $buf->readLine(EventBuffer::EOL_ANY)) {
|
|
echo $s, PHP_EOL;
|
|
}
|
|
echo "Não há mais dados no buffer\n";
|
|
}
|
|
|
|
function _http_about($req) {
|
|
echo __METHOD__, PHP_EOL;
|
|
echo "URI: ", $req->getUri(), PHP_EOL;
|
|
echo "\n >> Enviando resposta ...";
|
|
$req->sendReply(200, "OK");
|
|
echo "OK\n";
|
|
}
|
|
|
|
function _http_default($req, $data) {
|
|
echo __METHOD__, PHP_EOL;
|
|
echo "URI: ", $req->getUri(), PHP_EOL;
|
|
echo "\n >> Enviando resposta ...";
|
|
$req->sendReply(200, "OK");
|
|
echo "OK\n";
|
|
}
|
|
|
|
$port = 8010;
|
|
if ($argc > 1) {
|
|
$port = (int) $argv[1];
|
|
}
|
|
if ($port <= 0 || $port > 65535) {
|
|
exit("Porta inválida");
|
|
}
|
|
|
|
$base = new EventBase();
|
|
$http = new EventHttp($base);
|
|
$http->setAllowedMethods(EventHttpRequest::CMD_GET | EventHttpRequest::CMD_POST);
|
|
|
|
$http->setCallback("/dump", "_http_dump", array(4, 8));
|
|
$http->setCallback("/about", "_http_about");
|
|
$http->setDefaultCallback("_http_default", "valor de dados personalizados");
|
|
|
|
$http->bind("0.0.0.0", 8010);
|
|
$base->loop();
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
a=12
|
|
HTTP/1.0 200 OK
|
|
Content-Type: text/html; charset=ISO-8859-1
|
|
Connection: close
|
|
|
|
HTTP/1.0 200 OK
|
|
Content-Type: text/html; charset=ISO-8859-1
|
|
Connection: close
|
|
(pressione Enter)
|
|
|
|
HTTP/1.0 200 OK
|
|
Content-Type: text/html; charset=ISO-8859-1
|
|
Connection: close
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|