Learning and understanding of PHP input/output stream

Source: Internet
Author: User
Tags wrappers
Learning and understanding of PHP input/output streams php: //-accessing various input/output streams (I/Ostreams) PHP provides some miscellaneous input/output (IO) stream, which allows access to PHP input and output streams, standard input and output, and error descriptors. the memory and disk learn and understand the PHP input and output streams.
Php ://

Php: //-access each input/output stream (I/O streams)

PHP provides some miscellaneous input/output (IO) streams that allow access to PHP input/output streams, standard input/output, and error descriptors, memory, temporary file streams backed up by disks, and filters that can be used to read and write file resources.

?

Php: // stdin, php: // stdout and php: // stderr

Php: // stdin,Php: // stdoutAndPhp: // stderrAllow direct access to the input or output stream of the PHP process. The data stream references the copied file descriptor, so if you openPhp: // stdinAnd then shut it down. only the replica is closed and actually referenced.STDINNot affected. Note that PHP has many bugs in this regard until PHP 5.2.1. We recommend that you use constants.STDIN,STDOUTAndSTDERRIn place of manually opening these wrappers.

Php: // stdinIs read-only,Php: // stdoutAndPhp: // stderrWrite-only.

?

Php: // input

Php: // inputIs a read-only stream that can access the requested raw data. In case of POST requests, it is best to usePhp: // inputTo replace$ HTTP_RAW_POST_DATABecause it does not depend on specificPhp. iniCommand. In this case$ HTTP_RAW_POST_DATANo memory is filled by default, which requires less memory than activating always_populate_raw_post_data.Enctype = "multipart/form-data"TimePhp: // inputIs invalid.

Note:Php: // inputThe opened data stream can only be read once. The data stream does not support the seek operation. However, depending on the implementation of SAPI, when the request body data is saved, it can open anotherPhp: // inputData streams and read them again. Generally, this is only for POST requests, rather than other request methods, such as PUT or PROPFIND.

?

Php: // output

Php: // outputIs a write-only data stream that allows you to write data to the output buffer in the same way as print and echo.

?

Php: // fd

Php: // fdAllow direct access to the specified file descriptor. For examplePhp: // fd/3File descriptor 3 is referenced.

?

Php: // memory and php: // temp

Php: // memoryAndPhp: // tempIs a data stream similar to the file wrapper that allows reading and writing temporary data. The only difference between the two is thatPhp: // memoryData is always stored in the memory, whilePhp: // tempAfter the internal storage reaches the predefined limit (2 MB by default), it is saved to the temporary file. The temporary file location is determined in the same way as sys_get_temp_dir.

Php: // tempYou can add/Maxmemory: NNTo control,NNIt is the maximum data size retained in memory in bytes. if the size exceeds the limit, a temporary file is used.

?

Php: // filter

Php: // filterIt is a metadatile designed for filtering applications when data streams are opened. This is very useful for all-in-one file functions, such as readfile (), file (), and file_get_contents (). other filters are not used before reading data streams.

Php: // filterThe target uses the following parameters as part of its path. The compound filter chain can be specified on a path. For details about how to use these parameters, refer to the specific example.

?

Php: // filter parameters Name description
Resource = <要过滤的数据流> This parameter is required. It specifies the data stream you want to filter.
Read = <读链的筛选列表> This parameter is optional. You can set one or more filter names as pipe characters (|.
Write = <写链的筛选列表> This parameter is optional. You can set one or more filter names as pipe characters (|.
<; Filtering list of two chains> AnyRead =OrWrite =The filter list prefix applies to the read or write chain as needed.

?

Optional
Encapsulation Protocol summary (Php: // filter, Refer to the encapsulated filter .) Attribute support
First, use allow_url_fopen No
First, use allow_url_include OnlyPhp: // input,Php: // stdin,Php: // memoryAndPhp: // temp.
Read allowed OnlyPhp: // stdin,Php: // input,Php: // fd,Php: // memoryAndPhp: // temp.
Write allowed OnlyPhp: // stdout,Php: // stderr,Php: // output,Php: // fd,Php: // memoryAndPhp: // temp.
Append allowed OnlyPhp: // stdout,Php: // stderr,Php: // output,Php: // fd,Php: // memoryAndPhp: // temp(Equal to write)
Allow simultaneous read/write OnlyPhp: // fd,Php: // memoryAndPhp: // temp.
Support stat () OnlyPhp: // memoryAndPhp: // temp.
Supports unlink () No
Support rename () No
Supports mkdir () No
Supports rmdir () No
Only stream_select () is supported () Php: // stdin,Php: // stdout,Php: // stderr,Php: // fdAndPhp: // temp.

?

Example

Example #1 php: // temp/maxmemory

This option can be set.Php: // tempMaximum memory limit before using temporary files.

 

?

Example #2 php: // filter/resource = <待过滤的数据流>

This parameter must be locatedPhp: // filterAnd point to the data stream to be filtered.

 

?

Example #3 php: // filter/read = <读链需要应用的过滤器列表>

This parameter uses one or more pipe characters.|Multiple filter names.

 

?

Example #4 php: // filter/write = <写链需要应用的过滤器列表>

This parameter uses one or more pipe characters.|Multiple filter names.

 

?

Address: http://www.php.net/manual/zh/wrappers.php.php

?

PHP 3.0.13And later versions, fromPHP 4.3.0Startup supportPhp: // outputAndPhp: // input, FromPHP 5.0.0Startup supportPhp: // filter.

  • Php: // stdin

  • Php: // stdout

  • Php: // stderr

  • Php: // output

  • Php: // input

  • Php: // filter

Php: // stdin,Php: // stdoutAndPhp: // stderrAllow access to the input or output stream of the PHP process.

Php: // outputAllows writing data to the output buffer, andPrint ()AndEcho ().

Php: // inputAllows you to read original POST data. And$ HTTP_RAW_POST_DATACompared to memory, it puts less pressure on memory and does not require any specialPhp. ini.

Php: // stdinAndPhp: // inputIs read-only, at the same time,Php: // stdout,Php: // stderrAndPhp: // outputWrite-only.

Php: // filterIt is an encapsulation protocol designed to allow a filter program to flow when it is opened. This is for file functions that have individual complete functions, suchReadfile (),File ()AndFile_get_contents ()It is useful, otherwise it will not be able to apply the filter to the stream before reading the content.

Php: // filterThe target accepts the subsequent 'parameters' as part of its 'path.

  • /Resource = (Required) This parameter must be locatedPhp: // filterAnd point to the stream to be filtered.

        

    ?

  • /Read = (Optional) This parameter accepts the names of one or more filters, using pipeline characters.|Separated.

        

    ?

  • /Write = (Optional) This parameter accepts the names of one or more filters, using pipeline characters.|Separated.

        

    ?

  • / (Optional) AnyRead =OrWrite =The specified filter is applied to the read/write chain at the same time.

?

Table J-5. Wrapper Summary (Php: // filter, Refer to summary of wrapper being filtered .)

Attribute support
RestrictedAllow_url_fopen. No
Allows Reading Php: // stdinAndPhp: // inputOnly.
Allows Writing Php: // stdout,Php: // stderr, AndPhp: // outputOnly.
Allows Appending Php: // stdout,Php: // stderr, AndPhp: // outputOnly. (Equivalent to writing)
Allows Simultaneous Reading and Writing No. These wrappers are unidirectional.
SupportsStat () No
SupportsUnlink () No

?

Original article: http://php.jz123.cn/wrappers.php.html

?

?

?

?

?

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.