Document the stream notification parameter

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@257436 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Hannes Magnusson 2008-04-14 08:23:27 +00:00
parent 7d7d82921b
commit f04814d2d9
2 changed files with 216 additions and 33 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<chapter xml:id="stream.contexts">
<chapter xml:id="stream.contexts" xmlns="http://docbook.org/ns/docbook">
<title>Stream Contexts</title>
<simpara>
A <literal>context</literal> is a set of <literal>parameters</literal> and
@ -15,39 +15,13 @@
<literal>Options</literal> can be specified when calling
<function>stream_context_create</function>, or later using
<function>stream_context_set_option</function>.
A list of wrapper specific <literal>options</literal> can be found with
the list of built-in wrappers (See <xref linkend="wrappers"/>).
A list of wrapper specific <literal>options</literal> can be found in the
<xref linkend="context" /> chapter.
</simpara>
<simpara>
In addition, <literal>parameters</literal> may be set on a <literal>context</literal>
using <function>stream_context_set_params</function>. Currently the only
<literal>context parameter</literal> supported by PHP is
<literal>notification</literal>. The value of this parameter must be the
name of a function to be called when an event occurs on a stream.
The notification function called during an event should accept the following
six parameters:
</simpara>
<methodsynopsis>
<type>void</type><methodname>my_notifier</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>
<simpara>
<parameter>notification_code</parameter> and <parameter>severity</parameter>
are numerical values which correspond to the <constant>STREAM_NOTIFY_*</constant>
constants listed below.
If a descriptive message is available from the stream, <parameter>message</parameter>
and <parameter>message_code</parameter> will be populated with the appropriate values.
The meaning of these values is dependent on the specific wrapper in use.
<parameter>bytes_transferred</parameter> and <parameter>bytes_max</parameter> will
be populated when applicable.
<literal>Parameters</literal> can be specified for
<literal>contexts</literal> using the
<function>stream_context_set_params</function> function.
</simpara>
</chapter>

View file

@ -0,0 +1,209 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.1 $ -->
<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>A callback function for the <literal>notification</literal> context paramater</refpurpose>
</refnamediv>
<refsect1 role="description"><!-- {{{ -->
&reftitle.description;
<methodsynopsis>
<type>void</type><methodname>stream_notification_callback</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>
A <type>callback</type> function called during an event.
</para>
<note>
<para>
This is note a real function, only a prototype of how the function should
be.
</para>
</note>
</refsect1><!-- }}} -->
<refsect1 role="parameters"><!-- {{{ -->
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>notification_code</parameter></term>
<listitem>
<para>
One of the <constant>STREAM_NOTIFY_*</constant> notification constants.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>severity</parameter></term>
<listitem>
<para>
One of the <constant>STREAM_NOTIFY_SEVERITY_*</constant> notification constants.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<para>
Passed if a descriptive message is available for the event.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>message_code</parameter></term>
<listitem>
<para>
Passed if a descriptive message code is available for the event.
</para>
<para>
The meaning of this value is dependent on the specific wrapper in use.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>bytes_transferred</parameter></term>
<listitem>
<para>
If applicable, the <parameter>bytes_transferred</parameter> will be
populated.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>bytes_max</parameter></term>
<listitem>
<para>
If applicable, the <parameter>bytes_transferred</parameter> will be
populated.
</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><function>stream_notification_callback</function> example</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 "Being redirected to: ", $message;
break;
case STREAM_NOTIFY_CONNECT:
echo "Conntected...";
break;
case STREAM_NOTIFY_FILE_SIZE_IS:
echo "Got the filesize: ", $bytes_max;
break;
case STREAM_NOTIFY_MIME_TYPE_IS:
echo "Found the mime-type: ", $message;
break;
case STREAM_NOTIFY_PROGRESS:
echo "Made some progress, downloaded ", $bytes_transferred, " so far";
break;
}
echo "\n";
}
$ctx = stream_context_create(null, array("notification" => "stream_notification_callback"));
file_get_contents("http://php.net/contact", false, $ctx);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Conntected...
Found the mime-type: text/html; charset=utf-8
Being redirected to: http://no.php.net/contact
Conntected...
Got the filesize: 0
Found the mime-type: text/html; charset=utf-8
Being redirected to: http://no.php.net/contact.php
Conntected...
Got the filesize: 4589
Found the mime-type: text/html;charset=utf-8
Made some progress, downloaded 0 so far
Made some progress, downloaded 0 so far
Made some progress, downloaded 0 so far
Made some progress, downloaded 1440 so far
Made some progress, downloaded 2880 so far
Made some progress, downloaded 4320 so far
Made some progress, downloaded 5760 so far
Made some progress, downloaded 6381 so far
Made some progress, downloaded 7002 so far
]]>
</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:"../../../../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
-->