Streams stream_get_meta_data

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

stream_get_meta_data — 스트림/파일 포인터에서 헤더/메타 데이터 검색


설명

stream_get_meta_data(resource $stream): array

기존 stream에 대한 정보를 반환합니다.


매개변수

stream
스트림은 fopen(), fsockopen(), pfsockopen()stream_socket_client()에 의해 생성된 모든 스트림이 될 수 있습니다.

반환 값

결과 배열에는 다음 항목이 포함됩니다.

  • timed_out (bool) - fread() 또는 fgets()에 대한 마지막 호출에서 데이터를 기다리는 동안 스트림이 시간 초과되면 true 입니다.
  • blocked (bool) - 스트림이 차단 IO 모드에 있으면 true입니다. stream_set_blocking()을 참조하십시오.
  • eof (bool) - 스트림이 파일 끝에 도달한 경우 true입니다. 소켓 스트림의 경우 이 멤버는 unread_bytes가 0이 아닌 경우에도 true일 수 있습니다. 읽을 데이터가 더 있는지 확인하려면 이 항목을 읽는 대신 feof()를 사용하십시오.
  • unread_bytes (int) - PHP 자체 내부 버퍼에 현재 포함된 바이트 수.

    참고: 스크립트에서 이 값을 사용하면 안 됩니다.

  • stream_type (string) - 스트림의 기본 구현을 설명하는 레이블입니다.
  • wrapper_type (string) - 스트림 위에 계층화된 프로토콜 래퍼 구현을 설명하는 레이블입니다. 래퍼에 대한 자세한 내용은 Supported Protocols and Wrappers를 참조하세요.
  • wrapper_data (mixed) - 이 스트림에 첨부된 래퍼 특정 데이터입니다. 래퍼 및 래퍼 데이터에 대한 자세한 내용은 Supported Protocols and Wrappers를 참조하세요.
  • mode (string) - 이 스트림에 필요한 액세스 유형(fopen() 참조의 표 1 참조)
  • seekable (bool) - 현재 스트림을 찾을 수 있는지 여부.
  • uri (string) - 이 스트림과 관련된 URI/파일 이름.
  • crypto (array) - 이 스트림에 대한 TLS 연결 메타데이터입니다. (참고: 리소스의 스트림이 TLS를 사용하는 경우에만 제공됩니다.)

Examples

예제 #1 http와 함께 fopen()을 사용하는 stream_get_meta_data() 예제

                  
<?php
$url = 'http://www.example.com/';

if (!$fp = fopen($url, 'r')) {
    trigger_error("Unable to open URL ($url)", E_USER_ERROR);
}

$meta = stream_get_meta_data($fp);

var_dump($meta);

fclose($fp);
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

array(10) {
  'timed_out' =>
  bool(false)
  'blocked' =>
  bool(true)
  'eof' =>
  bool(false)
  'wrapper_data' =>
  array(13) {
    [0] =>
    string(15) "HTTP/1.1 200 OK"
    [1] =>
    string(11) "Age: 244629"
    [2] =>
    string(29) "Cache-Control: max-age=604800"
    [3] =>
    string(38) "Content-Type: text/html; charset=UTF-8"
    [4] =>
    string(35) "Date: Sat, 20 Nov 2021 18:17:57 GMT"
    [5] =>
    string(24) "Etag: "3147526947+ident""
    [6] =>
    string(38) "Expires: Sat, 27 Nov 2021 18:17:57 GMT"
    [7] =>
    string(44) "Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT"
    [8] =>
    string(22) "Server: ECS (chb/0286)"
    [9] =>
    string(21) "Vary: Accept-Encoding"
    [10] =>
    string(12) "X-Cache: HIT"
    [11] =>
    string(20) "Content-Length: 1256"
    [12] =>
    string(17) "Connection: close"
  }
  'wrapper_type' =>
  string(4) "http"
  'stream_type' =>
  string(14) "tcp_socket/ssl"
  'mode' =>
  string(1) "r"
  'unread_bytes' =>
  int(1256)
  'seekable' =>
  bool(false)
  'uri' =>
  string(23) "http://www.example.com/"
}
                

예제 #2 https와 함께 stream_socket_client()를 사용하는 stream_get_meta_data() 예제

                  
<?php
$streamContext = stream_context_create(
    [
        'ssl' => [
            'capture_peer_cert' => true,
            'capture_peer_cert_chain' => true,
            'disable_compression' => true,
        ],
    ]
);

$client = stream_socket_client(
    'ssl://www.example.com:443',
    $errorNumber,
    $errorDescription,
    40,
    STREAM_CLIENT_CONNECT,
    $streamContext
);


$meta = stream_get_meta_data($client);

var_dump($meta);
?>
                  
                

위의 예는 다음과 유사한 결과를 출력합니다.

array(8) {
  'crypto' =>
  array(4) {
    'protocol' =>
    string(7) "TLSv1.3"
    'cipher_name' =>
    string(22) "TLS_AES_256_GCM_SHA384"
    'cipher_bits' =>
    int(256)
    'cipher_version' =>
    string(7) "TLSv1.3"
  }
  'timed_out' =>
  bool(false)
  'blocked' =>
  bool(true)
  'eof' =>
  bool(false)
  'stream_type' =>
  string(14) "tcp_socket/ssl"
  'mode' =>
  string(2) "r+"
  'unread_bytes' =>
  int(0)
  'seekable' =>
  bool(false)
}
                

메모

메모: 이 함수는 Socket 확장에 의해 생성된 소켓에서 작동하지 않습니다.


기타