svn: /phpdoc/es/trunk/reference/eio/ examples.xml

From: Date: Wed, 02 Nov 2011 18:05:34 +0000
Subject: svn: /phpdoc/es/trunk/reference/eio/ examples.xml
Groups: php.doc.es 
Request: Send a blank email to doc-es+get-5132@lists.php.net to get a copy of this message
seros Wed, 02 Nov 2011 18:05:34 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=318700 Log: Translation Changed paths: A phpdoc/es/trunk/reference/eio/examples.xml Added: phpdoc/es/trunk/reference/eio/examples.xml =================================================================== --- phpdoc/es/trunk/reference/eio/examples.xml (rev 0) +++ phpdoc/es/trunk/reference/eio/examples.xml 2011-11-02 18:05:34 UTC (rev 318700) @@ -0,0 +1,279 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- $Revision$ --> +<!-- EN-Revision: 318491 Maintainer: seros Status: ready --> +<!-- Reviewed: no --> + +<chapter xml:id="eio.examples" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> + &reftitle.examples; + <para> + <example> + <title>Cancelar una petición</title> + <programlisting role="php"> +<![CDATA[ + <?php + /* Es llamada cuando finaliza eio_nop() */ + function mi_nop_cb($datos, $resultado) { + echo "mi_nop ", $datos, "\n"; + } + +// Esta llamada a eio_nop() será cancelada +$petición = eio_nop(EIO_PRI_DEFAULT, "mi_nop_cb", "1"); +var_dump($petición); +eio_cancel($petición); + +// Esta vez eio_nop() será procesada +eio_nop(EIO_PRI_DEFAULT, "mi_nop_cb", "2"); + +// Process requests +eio_event_loop(); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +resource(4) of type (EIO Request Descriptor) +mi_nop 2 + ]]> + </screen> + </example> + </para> + + <para> + <example> + <title>Llamar a <function>eio_chmod</function></title> + <programlisting role="php"> +<![CDATA[ +<?php +$nombre_fichero_temp = "eio-fichero-temp.tmp"; +touch($nombre_fichero_temp); + +/* Es llamada cuando finaliza eio_chmod() */ +function mi_llamada_retorno_chmod($datos, $resultado) { + global $nombre_fichero_temp; + + if ($resultado == 0 && !is_readable($nombre_fichero_temp) && is_writable($nombre_fichero_temp)) { + echo "eio_chmod_ok"; + } + + @unlink($nombre_fichero_temp); +} + +eio_chmod($nombre_fichero_temp, 0200, EIO_PRI_DEFAULT, "mi_llamada_retorno_chmod"); +eio_event_loop(); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +eio_chmod_ok + ]]> + </screen> + </example> + </para> + + <para> + <example> + <title>Realizar una petición personalizada</title> + <programlisting role="php"> +<![CDATA[ +<?php +/* Llamada de retorno para la llamada de retorno personalizada */ +function mi_llamada_retorno_personalizada($datos, $resultado) { + var_dump($datos); + var_dump(count($resultado)); + var_dump($resultado['data_modified']); + var_dump($resultado['result']); +} + +/* La petición personalizada */ +function mi_personalizada($datos) { + var_dump($datos); + + $resultado = array( + 'result' => 1001, + 'data_modified' => "mis datos personalizados", + ); + + return $resultado; +} + +$datos = "mis_datos_personalizados"; +$petición = eio_custom("mi_personalizada", EIO_PRI_DEFAULT, "mi_llamada_retorno_personalizada", $datos); +var_dump($petición); +eio_event_loop(); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +resource(4) of type (EIO Request Descriptor) +string(24) "mis_datos_personalizados" +string(24) "mis_datos_personalizados" +int(2) +string(24) "mis datos personalizados" +int(1001) + ]]> + </screen> + </example> + </para> + + <para> + <example> + <title>Agrupar peticiones</title> + <programlisting role="php"> +<![CDATA[ +<?php +/* + * Crear un grupo de peticiones para abrir, leer y cerrar un fichero + */ + +$nombre_fichero_temp = dirname(__FILE__) ."/eio-file.tmp"; +$fp = fopen($nombre_fichero_temp, "w"); +fwrite($fp, "algunos datos"); +fclose($fp); + +/* Es llamada cuando el grupo de peticiones está hecho */ +function mi_grupo_hecho($datos, $resultado) { + global $nombre_fichero_temp; + var_dump($resultado == 0); + @unlink($nombre_fichero_temp); +} + +/* Es llamada cuando eio_open() termina */ +function mi_grupo_llamada_retorno_fichero_abierto($datos, $resultado) { + global $mi_df_fichero, $grupo; + + $mi_df_fichero = $resultado; + + var_dump($resultado > 0); + + // Crear una petición eio_read() y añadirla al grupo + $petición = eio_read($mi_df_fichero, 4, 0, EIO_PRI_DEFAULT, "mi_grupo_llamada_retorno_fichero_leído"); + eio_grp_add($grupo, $petición); +} + +/* Is called when eio_read() done */ +function mi_grupo_llamada_retorno_fichero_leído($datos, $resultado) { + global $mi_df_fichero, $grupo; + + var_dump($resultado); + + // Crear una petición eio_close() y añadirla al grupo + $petición = eio_close($mi_df_fichero); + eio_grp_add($grupo, $petición); +} + +$grupo = eio_grp("mi_grupo_hecho", "mis_datos_grupo"); + +// Crear una petición eio_open() y añadirla al grupo +$petición = eio_open($nombre_fichero_temp, EIO_O_RDWR | EIO_O_APPEND , NULL, + EIO_PRI_DEFAULT, "mi_grupo_llamada_retorno_fichero_abierto", NULL); +eio_grp_add($grupo, $petición); +var_dump($grupo); + +eio_event_loop(); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +resource(6) of type (EIO Group Descriptor) +bool(true) +string(7) "algunos" +bool(true) + ]]> + </screen> + </example> + </para> + + <para> + <example> + <title>Usar eio con libevent</title> + <programlisting role="php"><![CDATA[ +<?php +function mi_eio_poll($df, $eventos, $argumentos) { + /* Algunas regulaciones de libevent podrían ir aquí .. */ + if (eio_nreqs()) { + eio_poll(); + } + /* .. y aquí */ +} + +function my_nop_cb($d, $r) { + var_dump($r); var_dump($d); +} + +$base = event_base_new(); +$evento = event_new(); + +// Obtener el descriptor de fichero de eio +$df = eio_get_eventfd(); +var_dump($df); + +eio_nop(EIO_PRI_DEFAULT, "my_nop_cb", "nop data"); +eio_mkdir("/tmp/abc-eio-temp", 0750, EIO_PRI_DEFAULT, "my_nop_cb", "nop data"); +/* algunas llamadas eio_* aquí ... */ + + +// establecer las banderas del evento +event_set($evento, $df, EV_READ /*| EV_PERSIST*/, "my_eio_poll", array($evento, $base)); + +// Establecer las propiedades del evento +event_base_priority_init($base, 10); + +// Establecer la base del evento +event_base_set($evento, $base); + +// Esto actualmente está en SVN, pero debería aparecer el la siguiente versión de +// libevent +event_priority_set($evento, 2); + +// habilitar el evento +event_add($evento); + +// iniciar el bucle de eventos +event_base_loop($base); + +/* Lo mismo estará disponible mediante interfaz libevent con buffer */ +?> +]]></programlisting> + + &example.outputs.similar; + <screen> +<![CDATA[ +int(3) +int(0) +string(8) "nop data" +int(0) +string(10) "mkdir data" + ]]> + </screen> + </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 +--> Property changes on: phpdoc/es/trunk/reference/eio/examples.xml ___________________________________________________________________ Added: svn:keywords + Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL Added: svn:eol-style + native

« previous php.doc.es (#5132) next »