php stream

定义:Stream Contexts

A context is a set of parameters and wrapper specific options which modify or enhance the behavior of a stream. Contexts are created using stream_context_create() and can be passed to most filesystem related stream creation functions (i.e. fopen(), file(), file_get_contents(), etc…).

常用法

resource stream_context_create ([ array $options [, array $params ]] )

array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

$fp = fopen('http://www.example.com', 'r', false, $context);
fpassthru($fp);
fclose($fp);

支持的协议
文件系统
Socket
HTTP 和 HTTPS
FTP 和 FTPS
PHP 输入/输出流
压缩流
Glob
Phar
Secure Shell 2
Rar
音频流
处理交互式流
支持的option:Context options and parameters
Socket context option listing
HTTP context option listing
FTP context option listing
SSL context option listing
CURL context option listing
Phar context option listing
Context parameter listing

Leave a Comment