mirror of
https://github.com/macintoshplus/doc-fr.git
synced 2026-03-25 17:32:07 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/fr/trunk@333830 c90b9560-bf6c-de11-be94-00142212c4b1
303 lines
9.1 KiB
XML
303 lines
9.1 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 4254b6dcb049722dac3b0df7714df3bad506317a Maintainer: yannick 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>Une fonction de rappel pour le paramètre de contexte <literal>notification</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>
|
|
Une fonction de rappel de type <type>callable</type>, utilisée par le
|
|
<link linkend="context.params.notification">paramètre de contexte notification</link>,
|
|
appelé lors d'un événement.
|
|
</para>
|
|
<note>
|
|
<para>
|
|
Ce n'est <emphasis>pas</emphasis> une réelle fonction, uniquement un prototype de la
|
|
façon dont la fonction doit être.
|
|
</para>
|
|
</note>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>notification_code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Une des constantes de notification <constant>STREAM_NOTIFY_*</constant>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>severity</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Une des constantes de notification <constant>STREAM_NOTIFY_SEVERITY_*</constant>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>message</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Passé si un message descriptif est disponible pour cet événement.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>message_code</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Passé si un code de message descriptif est disponible pour cet événement.
|
|
</para>
|
|
<para>
|
|
La signification de cette valeur dépend du gestionnaire spécifique utilisé.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>bytes_transferred</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si c'est possible, <parameter>bytes_transferred</parameter> sera rempli.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>bytes_max</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Si c'est possible, <parameter>bytes_max</parameter> sera rempli.
|
|
</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>Exemple avec <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 "Redirection vers : ", $message;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_CONNECT:
|
|
echo "Connecté...";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_FILE_SIZE_IS:
|
|
echo "Récupération de la taille du fichier : ", $bytes_max;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_MIME_TYPE_IS:
|
|
echo "Type mime trouvé : ", $message;
|
|
break;
|
|
|
|
case STREAM_NOTIFY_PROGRESS:
|
|
echo "En cours de téléchargement, déjà ", $bytes_transferred, " octets transférés";
|
|
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[
|
|
Connecté...
|
|
Type mime trouvé : text/html; charset=utf-8
|
|
Redirection vers : http://no.php.net/contact
|
|
Connecté...
|
|
Récupération de la taille du fichier : 0
|
|
Type mime trouvé : text/html; charset=utf-8
|
|
Redirection vers : http://no.php.net/contact.php
|
|
Connecté...
|
|
Récupération de la taille du fichier : 4589
|
|
Type mime trouvé : text/html;charset=utf-8
|
|
En cours de téléchargement, déjà 0 octets transférés
|
|
En cours de téléchargement, déjà 0 octets transférés
|
|
En cours de téléchargement, déjà 0 octets transférés
|
|
En cours de téléchargement, déjà 1440 octets transférés
|
|
En cours de téléchargement, déjà 2880 octets transférés
|
|
En cours de téléchargement, déjà 4320 octets transférés
|
|
En cours de téléchargement, déjà 5760 octets transférés
|
|
En cours de téléchargement, déjà 6381 octets transférés
|
|
En cours de téléchargement, déjà 7002 octets transférés
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example xml:id="stream-notification-callback.example.download">
|
|
<title>Barre de progression simple pour un client de téléchargement en ligne de commande</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
function usage($argv) {
|
|
echo "Utilisation :\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 "Redirection vers : ", $message, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_CONNECT:
|
|
echo "Connecté...\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_FILE_SIZE_IS:
|
|
$filesize = $bytes_max;
|
|
echo "Taille du fichier : ", $filesize, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_MIME_TYPE_IS:
|
|
echo "Type Mime : ", $message, "\n";
|
|
break;
|
|
|
|
case STREAM_NOTIFY_PROGRESS:
|
|
if ($bytes_transferred > 0) {
|
|
if (!isset($filesize)) {
|
|
printf("\rTaille du fichier inconnue.. %2d kb done..", $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 "\nFait !\n";
|
|
exit(0);
|
|
}
|
|
|
|
$err = error_get_last();
|
|
echo "\nErrrrreurr..\n", $err["message"], "\n";
|
|
exit(1);
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
<para>
|
|
Exécutez l'exemple ci-dessus avec :
|
|
<literal>php -n fetch.php
|
|
http://no2.php.net/get/php-5-LATEST.tar.bz2/from/this/mirror
|
|
php-latest.tar.bz2</literal> affichera quelque chose similaire à :
|
|
</para>
|
|
<screen>
|
|
<![CDATA[
|
|
Connecté...
|
|
Type Mime : text/html; charset=utf-8
|
|
Redirection vers : http://no2.php.net/distributions/php-5.2.5.tar.bz2
|
|
Connecté...
|
|
Taille du fichier : 7773024
|
|
Type 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
|
|
-->
|
|
|