$opt = array(
'http'=>array(
'timeout'=>10 //秒
)
)
file_get_contents('http://www.example.com',false,stream_context_create($opt))
参数说明
resource stream_context_create ([ array $options
[, array $params
]] )
file_get_contents(path,include_path,context,start,max_length)
参数 | 描述 |
---|---|
path | 必需。规定要读取的文件。 |
include_path | 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1"。 |
context | 可选。规定文件句柄的环境。 context 是一套可以修改流的行为的选项。若使用 null,则忽略。 |
start | 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。 |
max_length | 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。 |
fopen(filename,mode,include_path,context)
参数 | 描述 |
---|---|
filename | 必需。规定要打开的文件或 URL。 |
mode | 必需。规定要求到该文件/流的访问类型。可能的值见下表。 |
include_path | 可选。如果也需要在 include_path 中检索文件的话,可以将该参数设为 1 或 TRUE。 |
context | 可选。规定文件句柄的环境。Context 是可以修改流的行为的一套选项。 |