mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 16:32:13 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@317748 c90b9560-bf6c-de11-be94-00142212c4b1
112 lines
2.3 KiB
XML
112 lines
2.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 8b6d169424ff189bb563ef4c3f35f8adff3f42c5 Maintainer: edwincartagenah Status: ready -->
|
|
|
|
<chapter xml:id="libevent.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Votación con <constant>STDIN</constant> utilizando la API básica</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
function print_line($fd, $events, $arg)
|
|
{
|
|
static $max_requests = 0;
|
|
|
|
$max_requests++;
|
|
|
|
if ($max_requests == 10) {
|
|
// Salir del bucle después que escriba 10 veces
|
|
event_base_loopexit($arg[1]);
|
|
}
|
|
|
|
// Imprimir o mostrar la línea actual
|
|
echo fgets($fd);
|
|
}
|
|
|
|
// crear la base y el evento
|
|
$base = event_base_new();
|
|
$event = event_new();
|
|
|
|
$fd = STDIN;
|
|
|
|
// Colocar las banderas del evento
|
|
event_set($event, $fd, EV_READ | EV_PERSIST, "print_line", array($event, $base));
|
|
// Colocar la base del evento
|
|
event_base_set($event, $base);
|
|
|
|
// Habilitar el evento
|
|
event_add($event);
|
|
// Iniciar el bucle del evento
|
|
event_base_loop($base);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>Votación con <constant>STDIN</constant> utilizando la API de almacenamiento intermedio del evento</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
|
|
function print_line($buf, $arg)
|
|
{
|
|
static $max_requests;
|
|
|
|
$max_requests++;
|
|
|
|
if ($max_requests == 10) {
|
|
event_base_loopexit($arg);
|
|
}
|
|
|
|
// Imprimir o mostrar la línea actual
|
|
echo event_buffer_read($buf, 4096);
|
|
}
|
|
|
|
function error_func($buf, $what, $arg)
|
|
{
|
|
// Manejador de errores
|
|
}
|
|
|
|
$base = event_base_new();
|
|
$eb = event_buffer_new(STDIN, "print_line", NULL, "error_func", $base);
|
|
|
|
event_buffer_base_set($eb, $base);
|
|
event_buffer_enable($eb, EV_READ);
|
|
|
|
event_base_loop($base);
|
|
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</chapter>
|
|
|
|
<!-- 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
|
|
-->
|
|
|