简介 ¶
Streams are the way of generalizing file, network, data compression, and other operations which share a common set of functions and uses. In its simplest definition, a stream
is a resource
object which exhibits streamable behavior. That is, it can be read from or written to in a linear fashion, and may be able to fseek() to an arbitrary location within the stream.
A wrapper
is additional code which tells the stream how to handle specific protocols/encodings. For example, the http
wrapper knows how to translate a URL into an HTTP/1.0
request for a file on a remote server. There are many wrappers built into PHP by default (See 支持的协议和封装协议), and additional, custom wrappers may be added either within a PHP script using stream_wrapper_register(), or directly from an extension. Because any variety of wrapper may be added to PHP, there is no set limit on what can be done with them. To access the list of currently registered wrappers, use stream_get_wrappers().
A stream is referenced as: scheme
://target
scheme
(string) - The name of the wrapper to be used. Examples include: file, http, https, ftp, ftps, compress.zlib, compress.bz2, and php. See 支持的协议和封装协议 for a list of PHP built-in wrappers. If no wrapper is specified, the function default is used (typically file
://).target
- 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 支持的协议和封装协议 for a description of targets for built-in streams.
翻译:
简介 ¶
流是概括文件、网络、数据压缩 和 其他共享一组通用功能和用途的操作的方式。
在其最简单的定义中,流是表现出可流式行为的资源对象。也就是说,它可以以线性方式读取或写入,并且可以 fseek() 到流中的任意位置。
包装器是告诉流如何处理特定协议/编码的附加代码。
例如,http 包装器知道如何将 URL 转换为对远程服务器上文件的 HTTP/1.0 请求。
默认情况下,PHP 中内置了许多包装器(请参阅支持的协议和封装协议),另外,可以使用 stream_wrapper_register 在 PHP 脚本中添加自定义包装器,或者直接从扩展中添加自定义包装器。
因为任何种类的包装器都可以添加到 PHP 中,所以对它们可以做什么没有设定限制。
要访问当前注册的包装器列表,请使用 stream_get_wrappers()。
流被引用为:scheme://target
scheme(string) - 要使用的包装器的名称。
示例包括:file、http、https、ftp、ftps、compress.zlib、compress.bz2 和 php。
有关 PHP 内置包装器的列表,请参见支持的协议和封装。如果未指定包装器,则使用函数默认值(通常为 file://)。
目标 - 取决于使用的包装器。对于文件系统相关的流,这通常是所需文件的路径和文件名。对于网络相关的流,这通常是一个主机名,通常附加一个路径。同样,请参阅支持的协议和封装协议以了解内置流的目标描述。
➜ ~ php -r "print_r(stream_get_wrappers());"
Array
(
[0] => https
[1] => ftps
[2] => compress.zlib
[3] => compress.bzip2
[4] => php
[5] => file
[6] => glob
[7] => data
[8] => http
[9] => ftp
[10] => phar
[11] => zip
)
➜ ~
这其中,使用stream用过的有:
php,// 使用file_get_contents('php://input'); // 用来接收来自客户端的json格式请求
如:
当前端使用content-type: application/json格式
后端PHP接收请求参数的方式:
$data = json_decode(file_get_contents("php://input") ,true);
...