PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

stream_get_transports> <stream_get_line
Last updated: Fri, 10 Oct 2008

view this page in

stream_get_meta_data

(PHP 4 >= 4.3.0, PHP 5)

stream_get_meta_dataヘッダーあるいはメタデータをストリームまたはファイルポインタから取得する

説明

array stream_get_meta_data ( resource $stream )

既存の stream に関する情報を取得します。 ストリームは fopen() か、 fsockopen() か、pfsockopen() で 作成されたいずれのものも指定できます。 結果の配列は次のような項目を含みます。

  • timed_out (bool) - 最後に fread() または fgets() でデータを待っている時にタイムアウトした場合 TRUE を返します。

  • blocked (bool) - ストリームがブロック I/O モードの場合に TRUE となります。 stream_set_blocking() を参照ください。

  • eof (bool) - ストリームが EOF に 達した時 TRUE となります。 ストリームがソケットベースの場合、このメンバーは、 たとえ unread_bytes が 0 でなくても TRUE になる場合があることに注意してください。 まだデータがあるかどうかを調べるには、このパラメータではなく、 feof() を使ってください。

  • unread_bytes (int) - PHP の 内部バッファにあるデータのバイト数。

    注意: スクリプト中でこの値を使用すべきではありません。

次の項目は PHP 4.3.0 で追加されました。

  • stream_type (string) - ストリームの下層にある実装を表すラベル

  • wrapper_type (string) - ストリームを覆うプロトコルラッパを表すラベル。 ラッパについては サポートされるプロトコル/ラッパー を参照ください。

  • wrapper_data (mixed) - ストリームに付随しているラッパの固有のデータ。 ラッパとその固有の情報については、サポートされるプロトコル/ラッパー を参照ください。

  • filters (array) - ストリームに付加されているフィルタの名称を格納した配列。 フィルタに関するドキュメントは 利用できるフィルタのリスト にあります。

注意: この関数は PHP 4.3.0 で初めて導入されましたが、 それ以前には ソケットベースのストリーム専用の socket_get_status() を使い、 最初に挙げた 4 つの項目に関しては取得できました。
PHP 4.3.0 またはそれ以降では、 socket_get_status() はこの関数のエイリアスと なっています。

注意: この関数は ソケット関数 で作られたストリームに対しては機能しません。

次の項目は PHP 5.0.0 で追加されました。

  • mode (string) - このストリームに要求される アクセスモード(fopen() リファレンスの表 1 を参照ください)。

  • seekable (bool) - 現在のストリーム内で 移動が可能かどうか。

  • uri (string) - このストリームに関連付けられた URI / ファイル名。



add a note add a note User Contributed Notes
stream_get_meta_data
niels at nise81 dot com
03-Mar-2008 05:49
here is just an example how to read out all meta data.
how ever I found out that the "seekable"-entry doesn't exist in most of the streaming media files.

      if (!($fp = @fopen($url, 'r')))
         return NULL;

      $meta = stream_get_meta_data($fp);
     
          foreach(array_keys($meta) as $h){
              $v = $meta[$h];
              echo "".$h.": ".$v."<br/>";
              if(is_array($v)){
                  foreach(array_keys($v) as $hh){
                      $vv = $v[$hh];
                      echo "_".$hh.": ".$vv."<br/>";
                  }
              }
          }
      fclose($fp);
ed at readinged dot com
28-Jan-2003 07:54
Below is a function I wrote to pull the "Last-Modified" header from a given URL.  In PHP version 4.3 and above, it takes advantage of the stream_get_meta_data function, and in older version it uses a conventional GET procedure.  On failure to connect to $url, it returns NULL.  If the server does not return the Last-Modified header, it returns the current time.  All times are returned in PHP's integer format (seconds since epoch).

Use it as so:

$last_modified = stream_last_modified('http://www.php.net/news.rss');
if (!is_null($last_modified))
   if ($last_modified < time()-3600) //Older than an hour
      echo 'URL is older than an hour.';
   else
      echo 'URL is fairly new.';
else
   echo 'Invalid URL!';

function stream_last_modified($url)
{
   if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') > 0)
   {
      if (!($fp = @fopen($url, 'r')))
         return NULL;

      $meta = stream_get_meta_data($fp);
      for ($j = 0; isset($meta['wrapper_data'][$j]); $j++)
      {
         if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified'))
         {
            $modtime = substr($meta['wrapper_data'][$j], 15);
            break;
         }
      }
      fclose($fp);
   }
   else
   {
      $parts = parse_url($url);
      $host  = $parts['host'];
      $path  = $parts['path'];

      if (!($fp = @fsockopen($host, 80)))
         return NULL;

      $req = "HEAD $path HTTP/1.0\r\nUser-Agent: PHP/".phpversion()."\r\nHost: $host:80\r\nAccept: */*\r\n\r\n";
      fputs($fp, $req);

      while (!feof($fp))
      {
         $str = fgets($fp, 4096);
         if (strstr(strtolower($str), 'last-modified'))
         {
            $modtime = substr($str, 15);
            break;
         }
      }
      fclose($fp);
  }
   return isset($modtime) ? strtotime($modtime) : time();
}

stream_get_transports> <stream_get_line
Last updated: Fri, 10 Oct 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites