mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Finish moving streams documentation to its own section...
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@110044 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
6fec56a107
commit
c3196a1144
6 changed files with 861 additions and 0 deletions
120
reference/stream/functions/stream-get-meta-data.xml
Normal file
120
reference/stream/functions/stream-get-meta-data.xml
Normal file
|
@ -0,0 +1,120 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<refentry id="function.stream-get-meta-data">
|
||||
<refnamediv>
|
||||
<refname>stream_get_meta_data</refname>
|
||||
<refpurpose>Retrieves header/meta data from streams/file pointers</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>array</type><methodname>file_get_meta_data</methodname>
|
||||
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<simpara>
|
||||
Returns information about an existing <parameter>stream</parameter>.
|
||||
The stream can be any stream created by <function>fopen</function>,
|
||||
<function>fsockopen</function> and <function>pfsockopen</function>.
|
||||
The result array contains the following items:
|
||||
</simpara>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>timed_out</parameter> (bool) - &true; if the stream
|
||||
timed out while waiting for data on the last call to
|
||||
<function>fread</function> or <function>fgets</function>.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>blocked</parameter> (bool) - &true; if the stream is
|
||||
in blocking IO mode. See <function>socket_set_blocking</function>.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>eof</parameter> (bool) - &true; if the stream has reached
|
||||
end-of-file. Note that for socket streams this member can be &true;
|
||||
even when <parameter>unread_bytes</parameter> is non-zero. To
|
||||
determine if there is more data to be read, use
|
||||
<function>feof</function> instead of reading this item.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>unread_bytes</parameter> (int) - the number of bytes
|
||||
currently contained in the read buffer.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<simpara>
|
||||
The following items were added in PHP 4.3:
|
||||
</simpara>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>stream_type</parameter> (string) - a label describing
|
||||
the underlying implementation of the stream.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>wrapper_type</parameter> (string) - a label describing
|
||||
the protocol wrapper implementation layered over the stream.
|
||||
See <xref linkend="wrappers"/> for more information about wrappers.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>wrapper_data</parameter> (mixed) - wrapper specific
|
||||
data attached to this stream. See <xref linkend="wrappers"/> for
|
||||
more information about wrappers and their wrapper data.
|
||||
</para>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<para>
|
||||
<parameter>filters</parameter> (array) - and array containing
|
||||
the names of any filters that have been stacked onto this stream.
|
||||
Filters are currently undocumented.
|
||||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
<note>
|
||||
<para>
|
||||
This function was introduced in PHP 4.3, but prior to this version,
|
||||
<function>socket_get_status</function> could be used to retrieve
|
||||
the first four items, for <emphasis>socket based streams only</emphasis>.
|
||||
</para>
|
||||
<para>
|
||||
In PHP 4.3 and later,
|
||||
<function>socket_get_status</function> is an alias for this function.
|
||||
</para>
|
||||
</note>
|
||||
<note>
|
||||
<simpara>This function does NOT work on sockets created by the <link
|
||||
linkend="ref.sockets">Socket extension</link>.
|
||||
</simpara>
|
||||
</note>
|
||||
</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
|
||||
-->
|
320
reference/stream/functions/stream-register-wrapper.xml
Normal file
320
reference/stream/functions/stream-register-wrapper.xml
Normal file
|
@ -0,0 +1,320 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.141 -->
|
||||
<refentry id="function.stream-register-wrapper">
|
||||
<refnamediv>
|
||||
<refname>stream_register_wrapper</refname>
|
||||
<refpurpose>Register a URL wrapper implemented as a PHP class</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>boolean</type><methodname>stream_register_wrapper</methodname>
|
||||
<methodparam><type>string</type><parameter>protocol</parameter></methodparam>
|
||||
<methodparam><type>string</type><parameter>classname</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
<function>stream_register_wrapper</function> allows you to implement
|
||||
your own protocol handlers and streams for use with all the other
|
||||
filesystem functions (such as <function>fopen</function>,
|
||||
<function>fread</function> etc.).
|
||||
</para>
|
||||
<para>
|
||||
To implement a wrapper, you need to define a class with a number of
|
||||
member functions, as defined below. When someone fopens your stream,
|
||||
PHP will create an instance of <parameter>classname</parameter> and
|
||||
then call methods on that instance. You must implement the methods
|
||||
exactly as described below - doing otherwise will lead to undefined
|
||||
behaviour.
|
||||
</para>
|
||||
<para>
|
||||
<function>stream_register_wrapper</function> will return &false; if the
|
||||
<parameter>protocol</parameter> already has a handler.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>boolean</type><methodname>stream_open</methodname>
|
||||
<methodparam><type>string</type><parameter>path</parameter></methodparam>
|
||||
<methodparam><type>string</type><parameter>mode</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>options</parameter></methodparam>
|
||||
<methodparam><type>string</type><parameter>opened_path</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called immediately after your stream object is
|
||||
created. <parameter>path</parameter> specifies the URL that was
|
||||
passed to <function>fopen</function> and that this object is
|
||||
expected to retrieve. You can use <function>parse_url</function>
|
||||
to break it apart.
|
||||
</para>
|
||||
<para>
|
||||
<parameter>mode</parameter> is the mode used to open the file,
|
||||
as detailed for <function>fopen</function>. You are responsible
|
||||
for checking that <parameter>mode</parameter> is valid for the
|
||||
<parameter>path</parameter> requested.
|
||||
</para>
|
||||
<para>
|
||||
<parameter>options</parameter> holds additional flags set
|
||||
by the streams API. It can hold one or more of the following
|
||||
values OR'd together.
|
||||
<informaltable>
|
||||
<tgroup cols="2">
|
||||
<thead>
|
||||
<row>
|
||||
<entry>Flag</entry>
|
||||
<entry>Description</entry>
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>STREAM_USE_PATH</entry>
|
||||
<entry>If <parameter>path</parameter> is relative, search
|
||||
for the resource using the include_path.
|
||||
</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>STREAM_REPORT_ERRORS</entry>
|
||||
<entry>If this flag is set, you are responsible for raising
|
||||
errors using <function>trigger_error</function> during
|
||||
opening of the stream. If this flag is not set, you
|
||||
should not raise any errors.
|
||||
</entry>
|
||||
</row>
|
||||
</tbody>
|
||||
</tgroup>
|
||||
</informaltable>
|
||||
</para>
|
||||
<para>
|
||||
If the <parameter>path</parameter> is opened successfully,
|
||||
and STREAM_USE_PATH is set in <parameter>options</parameter>,
|
||||
you should set <parameter>opened_path</parameter> to the full
|
||||
path of the file/resource that was actually opened.
|
||||
</para>
|
||||
<para>
|
||||
If the requested resource was opened successfully, you should
|
||||
return &true;, otherwise you should return &false;
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>void</type><methodname>stream_close</methodname>
|
||||
<methodparam><type>void</type><parameter></parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called when the stream is closed, using
|
||||
<function>fclose</function>. You must release any resources
|
||||
that were locked or allocated by the stream.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>string</type><methodname>stream_read</methodname>
|
||||
<methodparam><type>int</type><parameter>count</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>fread</function>
|
||||
and <function>fgets</function> calls on the stream. You
|
||||
must return up-to <parameter>count</parameter> bytes of data
|
||||
from the current read/write position as a string.
|
||||
If there are less than <parameter>count</parameter>
|
||||
bytes available, return as many as are available. If no
|
||||
more data is available, return either &false; or an
|
||||
empty string.
|
||||
You must also update the read/write position of the stream
|
||||
by the number of bytes that were successfully read.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>int</type><methodname>stream_write</methodname>
|
||||
<methodparam><type>string</type><parameter>data</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>fwrite</function>
|
||||
calls on the stream. You should store <parameter>data</parameter>
|
||||
into the underlying storage used by your stream. If there is not
|
||||
enough room, try to store as many bytes as possible.
|
||||
You should return the number of bytes that were successfully
|
||||
stored in the stream, or 0 if none could be stored.
|
||||
You must also update the read/write position of the stream
|
||||
by the number of bytes that were successfully written.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>boolean</type><methodname>stream_eof</methodname>
|
||||
<methodparam><type>void</type><parameter></parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>feof</function>
|
||||
calls on the stream. You should return &true; if the read/write
|
||||
position is at the end of the stream and if no more data is available
|
||||
to be read, or &false; otherwise.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>int</type><methodname>stream_tell</methodname>
|
||||
<methodparam><type>void</type><parameter></parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>ftell</function>
|
||||
calls on the stream. You should return the current read/write
|
||||
position of the stream.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>boolean</type><methodname>stream_seek</methodname>
|
||||
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>whence</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>fseek</function>
|
||||
calls on the stream. You should update the read/write position
|
||||
of the stream according to <parameter>offset</parameter> and
|
||||
<parameter>whence</parameter>. See <function>fseek</function>
|
||||
for more information about these parameters.
|
||||
Return &true; if the position was updated, &false; otherwise.
|
||||
</para>
|
||||
|
||||
<methodsynopsis>
|
||||
<type>boolean</type><methodname>stream_flush</methodname>
|
||||
<methodparam><type>void</type><parameter></parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is called in response to <function>fflush</function>
|
||||
calls on the stream. If you have cached data in your stream
|
||||
but not yet stored it into the underlying storage, you should
|
||||
do so now.
|
||||
Return &true; if the cached data was successfully stored (or
|
||||
if there was no data to store), or &false; if the data could
|
||||
not be stored.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The example below implements a var:// protocol handler that
|
||||
allows read/write access to a named global variable using
|
||||
standard filesystem stream functions such as <function>fread</function>.
|
||||
The var:// protocol implemented below, given the url
|
||||
"var://foo" will read/write data to/from $GLOBALS["foo"].
|
||||
|
||||
<example>
|
||||
<title>A Stream for reading/writing global variables</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
class VariableStream {
|
||||
var $position;
|
||||
var $varname;
|
||||
|
||||
function stream_open($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
$url = parse_url($path);
|
||||
$this->varname = $url["host"];
|
||||
$this->position = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function stream_read($count)
|
||||
{
|
||||
$ret = substr($GLOBALS[$this->varname], $this->position, $count);
|
||||
$this->position += strlen($ret);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function stream_write($data)
|
||||
{
|
||||
$left = substr($GLOBALS[$this->varname], 0, $this->position);
|
||||
$right = substr($GLOBALS[$this->varname], $this->position + strlen($data));
|
||||
$GLOBALS[$this->varname] = $left . $data . $right;
|
||||
$this->position += strlen($data);
|
||||
return strlen($data);
|
||||
}
|
||||
|
||||
function stream_tell()
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
function stream_eof()
|
||||
{
|
||||
return $this->position >= strlen($GLOBALS[$this->varname]);
|
||||
}
|
||||
|
||||
function stream_seek($offset, $whence)
|
||||
{
|
||||
switch($whence) {
|
||||
case SEEK_SET:
|
||||
if ($offset < strlen($GLOBALS[$this->varname]) && $offset >= 0) {
|
||||
$this->position = $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
if ($offset >= 0) {
|
||||
$this->position += $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SEEK_END:
|
||||
if (strlen($GLOBALS[$this->varname]) + $offset >= 0) {
|
||||
$this->position = strlen($GLOBALS[$this->varname]) + $offset;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stream_register_wrapper("var", "VariableStream")
|
||||
or die("Failed to register protocol");
|
||||
|
||||
$myvar = "";
|
||||
|
||||
$fp = fopen("var://myvar", "r+");
|
||||
|
||||
fwrite($fp, "line1\n");
|
||||
fwrite($fp, "line2\n");
|
||||
fwrite($fp, "line3\n");
|
||||
|
||||
rewind($fp);
|
||||
while(!feof($fp)) {
|
||||
echo fgets($fp);
|
||||
}
|
||||
fclose($fp);
|
||||
var_dump($myvar);
|
||||
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</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
|
||||
-->
|
60
reference/stream/functions/stream-set-blocking.xml
Normal file
60
reference/stream/functions/stream-set-blocking.xml
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- splitted from ./en/functions/network.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.stream-set-blocking">
|
||||
<refnamediv>
|
||||
<refname>stream_set_blocking</refname>
|
||||
<refpurpose>Set blocking/non-blocking mode on a stream</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>bool</type><methodname>stream_set_blocking</methodname>
|
||||
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>mode</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
If <parameter>mode</parameter> is &false;, the given stream
|
||||
will be switched to non-blocking mode, and if &true;, it
|
||||
will be switched to blocking mode. This affects calls like
|
||||
<function>fgets</function> and <function>fread</function>
|
||||
that read from the stream. In non-blocking mode an
|
||||
<function>fgets</function> call will always return right away
|
||||
while in blocking mode it will wait for data to become available
|
||||
on the stream.
|
||||
</para>
|
||||
<para>
|
||||
This function was previously called as
|
||||
<function>set_socket_blocking</function> and later
|
||||
<function>socket_set_blocking</function> but this usage is deprecated.
|
||||
</para>
|
||||
<note>
|
||||
<simpara>
|
||||
Prior to PHP 4.3, this function only worked on socket based streams.
|
||||
Since PHP 4.3, this function works for any stream that supports
|
||||
non-blocking mode (currently, regular files and socket streams).
|
||||
</simpara>
|
||||
</note>
|
||||
</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
|
||||
-->
|
81
reference/stream/functions/stream-set-timeout.xml
Normal file
81
reference/stream/functions/stream-set-timeout.xml
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- splitted from ./en/functions/network.xml, last change in rev 1.18 -->
|
||||
<refentry id="function.stream-set-timeout">
|
||||
<refnamediv>
|
||||
<refname>stream_set_timeout</refname>
|
||||
<refpurpose>Set timeout period on a stream</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>bool</type><methodname>stream_set_timeout</methodname>
|
||||
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>seconds</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>microseconds</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
Sets the timeout value on <parameter>stream</parameter>,
|
||||
expressed in the sum of <parameter>seconds</parameter> and
|
||||
<parameter>microseconds</parameter>.
|
||||
<example>
|
||||
<title><function>stream_set_timeout</function> Example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$fp = fsockopen("www.example.com", 80);
|
||||
if(!$fp) {
|
||||
echo "Unable to open\n";
|
||||
} else {
|
||||
fputs($fp, "GET / HTTP/1.0\n\n");
|
||||
$start = time();
|
||||
stream_set_timeout($fp, 2);
|
||||
$res = fread($fp, 2000);
|
||||
var_dump(stream_get_meta_data($fp));
|
||||
fclose($fp);
|
||||
print $res;
|
||||
}
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<note>
|
||||
<simpara>
|
||||
As of PHP 4.3, this function can (potentially) work on any kind of
|
||||
stream. In PHP 4.3, socket based streams are still the only kind
|
||||
supported in the PHP core, although streams from other extensions
|
||||
may support this function.
|
||||
</simpara>
|
||||
</note>
|
||||
<para>
|
||||
This function was previously called as
|
||||
<function>set_socket_timeout</function> and later
|
||||
<function>socket_set_timeout</function> but this usage is deprecated.
|
||||
</para>
|
||||
<para>
|
||||
See also: <function>fsockopen</function> and <function>fopen</function>.
|
||||
</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
|
||||
-->
|
76
reference/stream/functions/stream-set-write-buffer.xml
Normal file
76
reference/stream/functions/stream-set-write-buffer.xml
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
|
||||
<refentry id="function.stream-set-write-buffer">
|
||||
<refnamediv>
|
||||
<refname>stream_set_write_buffer</refname>
|
||||
<refpurpose>Sets file buffering on the given stream</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<methodsynopsis>
|
||||
<type>int</type><methodname>stream_set_write_buffer</methodname>
|
||||
<methodparam><type>resource</type><parameter>stream</parameter></methodparam>
|
||||
<methodparam><type>int</type><parameter>buffer</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<simpara>
|
||||
Output using <function>fwrite</function> is normally buffered at
|
||||
8K. This means that if there are two processes wanting to write
|
||||
to the same output stream (a file), each is paused after 8K of
|
||||
data to allow the other to write.
|
||||
<function>stream_set_write_buffer</function>
|
||||
sets the buffering for write operations on the given filepointer
|
||||
<parameter>stream</parameter> to <parameter>buffer</parameter> bytes.
|
||||
If <parameter>buffer</parameter> is 0 then write operations are
|
||||
unbuffered. This ensures that all writes with
|
||||
<function>fwrite</function> are completed before other processes
|
||||
are allowed to write to that output stream.
|
||||
</simpara>
|
||||
<simpara>
|
||||
The function returns 0 on success, or EOF if the request cannot
|
||||
be honored.
|
||||
</simpara>
|
||||
<para>
|
||||
The following example demonstrates how to use
|
||||
<function>stream_set_write_buffer</function> to create an unbuffered stream.
|
||||
<example>
|
||||
<title><function>stream_set_write_buffer</function> example</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
$fp = fopen($file, "w");
|
||||
if ($fp) {
|
||||
stream_set_write_buffer($fp, 0);
|
||||
fputs($fp, $output);
|
||||
fclose($fp);
|
||||
}
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
|
||||
<simpara>
|
||||
See also <function>fopen</function> and <function>fwrite</function>.
|
||||
</simpara>
|
||||
</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
|
||||
-->
|
204
reference/stream/reference.xml
Normal file
204
reference/stream/reference.xml
Normal file
|
@ -0,0 +1,204 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.1 $ -->
|
||||
<reference id="ref.stream">
|
||||
<title>Stream functions</title>
|
||||
<titleabbrev>Streams</titleabbrev>
|
||||
|
||||
<partintro>
|
||||
|
||||
<section id="stream.intro">
|
||||
&reftitle.intro;
|
||||
<simpara>
|
||||
Streams were introduced with <literal>PHP</literal> 4.3.0 as
|
||||
a way of generalizing file, network, data compression, and other
|
||||
opperations which share a common set of functions and uses. In
|
||||
its simplest definition, a stream is any I/O conduit for exchanging
|
||||
information. Some streams work on the local filesystem, some
|
||||
use network connections (sockets), while others might potentially focus
|
||||
on communication devices such as printers or modems. Because any variety
|
||||
of stream may be added to <literal>PHP</literal> via the
|
||||
<function>stream_register_wrapper</function> function, there is no
|
||||
set limit on what can be done with them. See <xref linkend="wrappers"/>
|
||||
for a listing of stream wrappers built into <literal>PHP</literal>.
|
||||
</simpara>
|
||||
<para>
|
||||
A stream is referenced as: <parameter>scheme</parameter>://<parameter>target</parameter>
|
||||
<itemizedlist>
|
||||
<listitem>
|
||||
<simpara>
|
||||
<parameter>scheme</parameter>(string) -
|
||||
The name of the stream wrapper to be used. Examples include: file,
|
||||
http, https, ftp, ftps, compress.zlib, compress.bz2, ssl, tls, and php. See
|
||||
<xref linkend="wrappers"/> for a list of PHP builtin wrappers.
|
||||
</simpara>
|
||||
</listitem>
|
||||
<listitem>
|
||||
<simpara>
|
||||
<parameter>target</parameter> -
|
||||
Depends on the wrapper used. For filesystem related streams this is
|
||||
typically a path and filename of the desired file. For network related
|
||||
streams this is typically a hostname often with a path appended. Again, see
|
||||
<xref linkend="wrappers"/> for a description of targets for builtin streams.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</para>
|
||||
<simpara>
|
||||
Filters may also be applied to streams to further process data on its
|
||||
way into or out of a stream related call. Documentation on this
|
||||
functionality is comming soon.
|
||||
</simpara>
|
||||
</section>
|
||||
|
||||
<section id="stream.requirements">
|
||||
&reftitle.required;
|
||||
&no.requirement;
|
||||
</section>
|
||||
|
||||
<section id="stream.installation">
|
||||
&reftitle.install;
|
||||
<para>
|
||||
Streams are an integral part of <literal>PHP</literal>
|
||||
as of version 4.3.0. No steps are required to enable them.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="stream.configuration">
|
||||
&reftitle.runtime;
|
||||
&no.config;
|
||||
</section>
|
||||
|
||||
<section id="stream.resources">
|
||||
&reftitle.resources;
|
||||
&no.resource;
|
||||
</section>
|
||||
|
||||
<section id="stream.constants">
|
||||
&reftitle.constants;
|
||||
&no.constants;
|
||||
</section>
|
||||
|
||||
<section id="stream.errors">
|
||||
<title>Stream Errors</title>
|
||||
<para>
|
||||
As with any file or socket related function, an opperation on a stream
|
||||
may fail for a variety of normal reasons (i.e.: Unable to connect to remote
|
||||
host, file not found, etc...). A stream related call may also fail because
|
||||
the desired stream is not registered on the running system. See the output of
|
||||
<function>php_info</function> for a list of streams supported by your
|
||||
installation of <literal>PHP</literal>. As with most PHP internal functions
|
||||
if a failure occours an <constant>E_WARNING</constant> message will be generated
|
||||
describing the nature of the error.
|
||||
</para>
|
||||
</section>
|
||||
|
||||
<section id="sockets.examples">
|
||||
&reftitle.examples;
|
||||
<para>
|
||||
<example>
|
||||
<title>Using file_get_contents() to retrieve data from multiple sources</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
$localfile = file_get_contents("/home/bar/foo.txt"); // Read local file from /home/bar
|
||||
$localfile = file_get_contents("file:///home/bar/foo.txt"); // Identical to above, explicitly naming FILE scheme
|
||||
$httpfile = file_get_contents("http://www.example.com/foo.txt"); // Read remote file from www.example.com using HTTP
|
||||
$httpsfile = file_get_contents("https://www.example.com/foo.txt"); // Read remote file from www.example.com using HTTPS
|
||||
$ftpfile = file_get_contents("ftp://user:pass@ftp.example.com/foo.txt"); // Read remote file from ftp.example.com using FTP
|
||||
$ftpsfile = file_get_contents("ftps://user:pass@ftp.example.com/foo.txt"); // Read remote file from ftp.example.com using FTPS
|
||||
?>
|
||||
]]?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Making a POST request to an https server</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* Send POST request to https://secure.example.com/form_action.php
|
||||
* Include form elements named "foo" and "bar" with dummy values
|
||||
*/
|
||||
|
||||
$sock = fsockopen("ssl://secure.example.com", 443, $errno, $errstr, 30);
|
||||
if (!$sock) die("$errstr ($errno)\n";
|
||||
|
||||
$data = "foo=" . urlencode("Value for Foo") . "&bar=" . urlencode("Value for Bar");
|
||||
|
||||
fputs($sock, "POST /form_action.php HTTP/1.0\r\n");
|
||||
fputs($sock, "Host: secure.example.com\r\n");
|
||||
fputs($sock, "Content-type: application/x-www-url-encoded\r\n");
|
||||
fputs($sock, "Content-length: " . strlen($data) . "\r\n");
|
||||
fputs($sock, "Accept: */*\r\n");
|
||||
fputs($sock, "\r\n");
|
||||
fputs($sock, "$data\r\n");
|
||||
fputs($sock, "\r\n");
|
||||
|
||||
$headers = "";
|
||||
while ($str = trim(fgets($sock, 4096)))
|
||||
$headers .= "$str\n";
|
||||
|
||||
print "\n";
|
||||
|
||||
$body = "";
|
||||
while (!feof($sock))
|
||||
$body .= fgets($sock, 4096);
|
||||
|
||||
fclose($sock);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title>Writting data to a compressed file</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
/* Create a compressed file containing an arbitrarty string
|
||||
* File can be read back using compress.zlib stream or just
|
||||
* decompressed from the command line using 'gzip -d foo-bar.txt.gz'
|
||||
*/
|
||||
$fp = fopen("compress.zlib://foo-bar.txt.gz","w");
|
||||
if (!$fp) die("Unable to create file.");
|
||||
|
||||
fwrite($fp, "This is a test.\n");
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
</section>
|
||||
<simpara>
|
||||
For PHP Streams Development, See Also: <xref linkend="streams"/>
|
||||
</simpara>
|
||||
</partintro>
|
||||
|
||||
&reference.stream.functions;
|
||||
|
||||
</reference>
|
||||
<!-- 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
|
||||
-->
|
||||
|
Loading…
Reference in a new issue