PHP input/output stream learning notes
This article mainly introduces PHP input and output stream learning notes. PHP input and output streams are accessed through php, it allows access to PHP input and output streams, standard input and output, error descriptors, temporary file streams in memory, disk backup, and other filters that can read and write file resources, for more information, see
PHP input and output streams are accessed through php: //, which allows access to PHP input and output streams, standard input and 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: // stdout and php: // stderr allow access to the corresponding input or output stream of the PHP process.
Php: // input
Php: // input is a read-only stream that can access the requested raw data. In the case of POST requests, it is best to use php: // input to replace $ HTTP_RAW_POST_DATA (native post data), because it does not rely on specific php. ini instructions, and consumes less memory. For example:
?
1 2 3 4 5 6 |
<Form action = "" method = "post"> <Input type = "text" name = "test"> <input type = "submit" name = ""/> </Form> <? Php Echo file_get_contents ("php: // input "); ?> |
Result:
Php: // output
Php: // output is 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: // fd allows direct access to the specified file descriptor. For example, php: // fd/3 references file descriptor 3.
Php: // memory and php: // temp
Php: // memory and php: // temp are data streams similar to the file wrapper, allowing you to read and write temporary data. The only difference between the two is that php: // memory always stores data in the memory, while php: // temp will reach the predefined limit (2 MB by default) after the internal storage reaches the predefined limit) save it to a temporary file. The temporary file location is determined in the same way as sys_get_temp_dir.
Php: // filter
Php: // filter is a metadatabase that is 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. The parameters are as follows:
For example:
?
1 2 3 4 |
<? Php /* All contents of www.jb51.net will be output with uppercase letters */ Readfile ("php: // filter/read = string. toupper/resource = http://www.jb51.net "); ?> |