mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 08:22:08 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@333777 c90b9560-bf6c-de11-be94-00142212c4b1
305 lines
9.2 KiB
XML
305 lines
9.2 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 4254b6dcb049722dac3b0df7714df3bad506317a Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<refentry xml:id="function.stream-notification-callback" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>stream_notification_callback</refname>
|
|
<refpurpose>Una función de retrollamada para el parámetro de contexto de <literal>notificación</literal></refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description"><!-- {{{ -->
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>void</type><methodname><replaceable>stream_notification_callback</replaceable></methodname>
|
|
<methodparam><type>int</type><parameter>notification_code</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>severity</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>message</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>message_code</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>bytes_transferred</parameter></methodparam>
|
|
<methodparam><type>int</type><parameter>bytes_max</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Una función de tipo <type>callable</type>, usada por el
|
|
<link linkend="context.params.notification">parámetro de contexto de notificación</link>,
|
|
llamado durante un evento.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Esta <emphasis>no</emphasis> es una función real, sólo un prototipo de cómo la función debería
|
|
ser.
|
|
</para>
|
|
</note>
|
|
</refsect1><!-- }}} -->
|
|
|
|
<refsect1 role="parameters"><!-- {{{ -->
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>notification_code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Una de las constantes de notificación <constant>STREAM_NOTIFY_*</constant>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>severity</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Una de las constantes de notificación <constant>STREAM_NOTIFY_SEVERITY_*</constant>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>message</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Pasado si un mensaje descriptivo está disponible para el evento.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>message_code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Pasado si un código de mensaje descriptivo está disponible para el evento.
|
|
</para>
|
|
<para>
|
|
Esto significa que el valor depende de la envoltura específica en uso.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>bytes_transferred</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si se puede aplicar, el parámetro <parameter>bytes_transferred</parameter> será
|
|
rellenado.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>bytes_max</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si se puede aplicar, el parámetro <parameter>bytes_max</parameter> será
|
|
rellenado.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
</para>
|
|
</refsect1><!-- }}} -->
|
|
|
|
<refsect1 role="returnvalues"><!-- {{{ -->
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
&return.void;
|
|
</para>
|
|
</refsect1><!-- }}} -->
|
|
|
|
<refsect1 role="examples"><!-- {{{ -->
|
|
&reftitle.examples;
|
|
<para>
|
|
<example xml:id="stream-notification-callback.example.basic"><!-- {{{ -->
|
|
<title>Ejemplo de <function>stream_notification_callback</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
|
|
|
|
switch($notification_code) {
|
|
case STREAM_NOTIFY_RESOLVE:
|
|
case STREAM_NOTIFY_AUTH_REQUIRED:
|
|
case STREAM_NOTIFY_COMPLETED:
|
|
case STREAM_NOTIFY_FAILURE:
|
|
case STREAM_NOTIFY_AUTH_RESULT:
|
|
var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max);
|
|
/* Ignore */
|
|
break;
|
|
|
|
case STREAM_NOTIFY_REDIRECTED:
|
|
echo "Redireccionando a: ", $message;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_CONNECT:
|
|
echo "Conectado...";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_FILE_SIZE_IS:
|
|
echo "Obtenido el tamaño de archivo: ", $bytes_max;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_MIME_TYPE_IS:
|
|
echo "Encontrado el tipo mime: ", $message;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_PROGRESS:
|
|
echo "Hecho algún progreso, descargado ", $bytes_transferred, " hasta el momento";
|
|
break;
|
|
}
|
|
echo "\n";
|
|
}
|
|
|
|
$ctx = stream_context_create();
|
|
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
|
|
|
|
file_get_contents("http://php.net/contact", false, $ctx);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
Conectado...
|
|
Encontrado el tipo mime: text/html; charset=utf-8
|
|
Redireccionando a: http://no.php.net/contact
|
|
Conectado...
|
|
Obtenido el tamaño de archivo: 0
|
|
Found the mime-type: text/html; charset=utf-8
|
|
Redireccionando a: http://no.php.net/contact.php
|
|
Conectado...
|
|
Obtenido el tamaño de archivo: 4589
|
|
Encontrado el tipo mime: text/html;charset=utf-8
|
|
Hecho algún progreso, descargado 0 hasta el momento
|
|
Hecho algún progreso, descargado 0 hasta el momento
|
|
Hecho algún progreso, descargado 0 hasta el momento
|
|
Hecho algún progreso, descargado 1440 hasta el momento
|
|
Hecho algún progreso, descargado 2880 hasta el momento
|
|
Hecho algún progreso, descargado 4320 hasta el momento
|
|
Hecho algún progreso, descargado 5760 hasta el momento
|
|
Hecho algún progreso, descargado 6381 hasta el momento
|
|
Hecho algún progreso, descargado 7002 hasta el momento
|
|
]]>
|
|
</screen>
|
|
</example><!-- }}} -->
|
|
</para>
|
|
<para>
|
|
<example xml:id="stream-notification-callback.example.download"><!-- {{{ -->
|
|
<title>Barra de progreso sencilla para la descarga por parte del cliente por línea de comandos</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function usage($argv) {
|
|
echo "Uso:\n";
|
|
printf("\tphp %s <http://example.com/file> <localfile>\n", $argv[0]);
|
|
exit(1);
|
|
}
|
|
|
|
function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {
|
|
static $filesize = null;
|
|
|
|
switch($notification_code) {
|
|
case STREAM_NOTIFY_RESOLVE:
|
|
case STREAM_NOTIFY_AUTH_REQUIRED:
|
|
case STREAM_NOTIFY_COMPLETED:
|
|
case STREAM_NOTIFY_FAILURE:
|
|
case STREAM_NOTIFY_AUTH_RESULT:
|
|
/* Ignore */
|
|
break;
|
|
|
|
case STREAM_NOTIFY_REDIRECTED:
|
|
echo "Redireccionando a: ", $message, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_CONNECT:
|
|
echo "Conectado...\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_FILE_SIZE_IS:
|
|
$filesize = $bytes_max;
|
|
echo "Tamaño de archivo: ", $filesize, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_MIME_TYPE_IS:
|
|
echo "Tipo mime: ", $message, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_PROGRESS:
|
|
if ($bytes_transferred > 0) {
|
|
if (!isset($filesize)) {
|
|
printf("\rTamaño de archivo desconocido.. %2d kb hecho..", $bytes_transferred/1024);
|
|
} else {
|
|
$length = (int)(($bytes_transferred/$filesize)*100);
|
|
printf("\r[%-100s] %d%% (%2d/%2d kb)", str_repeat("=", $length). ">", $length, ($bytes_transferred/1024), $filesize/1024);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
isset($argv[1], $argv[2]) or usage($argv);
|
|
|
|
$ctx = stream_context_create();
|
|
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
|
|
|
|
$fp = fopen($argv[1], "r", false, $ctx);
|
|
if (is_resource($fp) && file_put_contents($argv[2], $fp)) {
|
|
echo "\n¡Hecho!\n";
|
|
exit(0);
|
|
}
|
|
|
|
$err = error_get_last();
|
|
echo "\nErrrrrorr..\n", $err["message"], "\n";
|
|
exit(1);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Ejecutar el ejemplo anterior con:
|
|
<literal>php -n fetch.php
|
|
http://no2.php.net/get/php-5-LATEST.tar.bz2/from/this/mirror
|
|
php-latest.tar.bz2</literal> imprimirá algo similar a:
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Conectado...
|
|
Tipo mime: text/html; charset=utf-8
|
|
Redireccionando a: http://no2.php.net/distributions/php-5.2.5.tar.bz2
|
|
Conectado...
|
|
Tamaño de archivo: 7773024
|
|
Tipo mime: application/octet-stream
|
|
[========================================> ] 40% (3076/7590 kb)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1><!-- }}} -->
|
|
|
|
<refsect1 role="seealso"><!-- {{{ -->
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><xref linkend="context.params" /></member>
|
|
</simplelist>
|
|
</para>
|
|
</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
|
|
-->
|
|
|