Streams stream_context_get_default
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
stream_context_get_default — 기본 스트림 컨텍스트 검색
설명
stream_context_get_default(?array $options
= null
): resource
파일 작업(fopen(), file_get_contents() 등...)이 컨텍스트 매개변수 없이 호출될 때마다 사용되는 기본 스트림 컨텍스트를 반환합니다. 기본 컨텍스트에 대한 옵션은 stream_context_create()와 동일한 구문을 사용하여 이 함수로 선택적으로 지정할 수 있습니다.
매개변수
options
options
는$arr['wrapper']['option'] = $value
또는null
형식의 연관 배열의 연관 배열이어야 합니다.
반환 값
스트림 컨텍스트 리소스입니다.
변경 로그
버전 | 설명 |
---|---|
8.0.0 | options 는 이제 nullable입니다. |
Examples
예제 #1 stream_context_get_default() 사용
<?php
$default_opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar",
'proxy'=>"tcp://10.54.1.39:8000"
)
);
$alternate_opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-length: " . strlen("baz=bomb"),
'content'=>"baz=bomb"
)
);
$default = stream_context_get_default($default_opts);
$alternate = stream_context_create($alternate_opts);
/* Sends a regular GET request to proxy server at 10.54.1.39
* For www.example.com using context options specified in $default_opts
*/
readfile('http://www.example.com');
/* Sends a POST request directly to www.example.com
* Using context options specified in $alternate_opts
*/
readfile('http://www.example.com', false, $alternate);
?>
기타
- stream_context_create() - 스트림 컨텍스트를 만듭니다.
- stream_context_set_default() - 기본 스트림 컨텍스트 설정
- 컨텍스트 옵션이 있는 지원되는 래퍼 목록(지원되는 프로토콜 및 래퍼)