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, 04 Jul 2008

view this page in

stream_get_meta_data

(PHP 4 >= 4.3.0, PHP 5)

stream_get_meta_data — Recupera meta datos/cabeceras desde apuntadores a secuencias/archivos

Descripción

array stream_get_meta_data ( resource $secuencia )

Devuelve información sobre una secuencia existente. La secuencia puede ser cualquiera creada por fopen(), fsockopen() y pfsockopen(). La matriz resultante contiene los siguientes items:

  • timed_out (bool) - TRUE si la secuencia ha superado el tiempo de espera máximo mientras esperaba datos en el último llamado a fread() o fgets().

  • blocked (bool) - TRUE si la secuencia se encuentra en modo de bloqueo de E/S. Vea stream_set_blocking().

  • eof (bool) - TRUE si la secuencia ha alcanzado el final del archivo. Note que para secuencias de socket, este miembro puede ser TRUE incluso cuando unread_bytes es diferente de cero. Para determinar si hay más datos para ser leidos, use feof() en lugar de leer este item.

  • unread_bytes (int) - el número de bytes contenidos actualmente en el búfer interno de PHP.

    Note: Este valor no debe ser usado en un script.

Los siguientes items fueron agregados en PHP 4.3.0:

  • stream_type (string) - una etiqueta que decribe la implementación de bajo nivel de la secuencia.

  • wrapper_type (string) - una etiqueta que describe la implementación de envoltura de protocolo que cubre a la secuencia. Vea Lista de Protocolos/Envolturas Soportadas para más información sobre las envolturas.

  • wrapper_data (mixed) - datos específicos de envoltura adjuntos a esta secuencia. Vea Lista de Protocolos/Envolturas Soportadas para más información sobre las envolturas y sus datos de envoltura.

  • filters (array) - una matriz que contiene los nombres de cualquier filtro que esté apilado para esta secuencia. La documentación sobre los filtros puede encontrarse en el apéndice de Filtros.

Note: Esta función fue introducida en PHP 4.3.0, pero anteriormente, socket_get_status() podía ser usado para recuperar los primeros cuatro items, para secuencias basadas en sockets únicamente.
En PHP 4.3.0 y versiones posteriores, socket_get_status() es un alias de esta función.

Note: Esta función NO trabaja sobre sockets creados por la Extensión de sockets.

Los siguientes ítems fueron agregados en PHP 5.0.0:

  • mode (string) - el tipo de acceso requerido para esta secuencia (vea la Tabla 1 de la referencia sobre fopen())

  • seekable (bool) - si la secuencia actual puede ser reubicada.

  • uri (string) - el nombre de archivo/URI asociado con esta secuencia.



add a note add a note User Contributed Notes
stream_get_meta_data
niels at nise81 dot com
03-Mar-2008 02: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
29-Jan-2003 04: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, 04 Jul 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites