<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Retrieves header/meta data from streams/file pointers</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-get-line.html">stream_get_line</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-get-transports.html">stream_get_transports</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.stream-get-meta-data" class="refentry"> <div class="refnamediv"> <h1 class="refname">stream_get_meta_data</h1> <p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">stream_get_meta_data</span> — <span class="dc-title">Retrieves header/meta data from streams/file pointers</span></p> </div> <div class="refsect1 description" id="refsect1-function.stream-get-meta-data-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>stream_get_meta_data</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stream</code></span> )</div> <p class="para rdfs-comment"> Returns information about an existing <em><code class="parameter">stream</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.stream-get-meta-data-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">stream</code></em></span> <dd> <p class="para"> The stream can be any stream created by <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span>, <span class="function"><a href="function.fsockopen.html" class="function">fsockopen()</a></span> and <span class="function"><a href="function.pfsockopen.html" class="function">pfsockopen()</a></span>. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.stream-get-meta-data-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The result array contains the following items: </p> <ul class="itemizedlist"> <li class="listitem"> <p class="para"> <em>timed_out</em> (bool) - <strong><code>TRUE</code></strong> if the stream timed out while waiting for data on the last call to <span class="function"><a href="function.fread.html" class="function">fread()</a></span> or <span class="function"><a href="function.fgets.html" class="function">fgets()</a></span>. </p> </li> <li class="listitem"> <p class="para"> <em>blocked</em> (bool) - <strong><code>TRUE</code></strong> if the stream is in blocking IO mode. See <span class="function"><a href="function.stream-set-blocking.html" class="function">stream_set_blocking()</a></span>. </p> </li> <li class="listitem"> <p class="para"> <em>eof</em> (bool) - <strong><code>TRUE</code></strong> if the stream has reached end-of-file. Note that for socket streams this member can be <strong><code>TRUE</code></strong> even when <em>unread_bytes</em> is non-zero. To determine if there is more data to be read, use <span class="function"><a href="function.feof.html" class="function">feof()</a></span> instead of reading this item. </p> </li> <li class="listitem"> <p class="para"> <em>unread_bytes</em> (int) - the number of bytes currently contained in the PHP's own internal buffer. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> You shouldn't use this value in a script. </span> </p></blockquote> </li> <li class="listitem"> <p class="para"> <em>stream_type</em> (string) - a label describing the underlying implementation of the stream. </p> </li> <li class="listitem"> <p class="para"> <em>wrapper_type</em> (string) - a label describing the protocol wrapper implementation layered over the stream. See <a href="wrappers.html" class="xref">Supported Protocols and Wrappers</a> for more information about wrappers. </p> </li> <li class="listitem"> <p class="para"> <em>wrapper_data</em> (mixed) - wrapper specific data attached to this stream. See <a href="wrappers.html" class="xref">Supported Protocols and Wrappers</a> for more information about wrappers and their wrapper data. </p> </li> <li class="listitem"> <p class="para"> <em>mode</em> (string) - the type of access required for this stream (see Table 1 of the <a href="function.fopen.html" class="link">fopen()</a> reference) </p> </li> <li class="listitem"> <p class="para"> <em>seekable</em> (bool) - whether the current stream can be seeked. </p> </li> <li class="listitem"> <p class="para"> <em>uri</em> (string) - the URI/filename associated with this stream. </p> </li> </ul> </div> <div class="refsect1 changelog" id="refsect1-function.stream-get-meta-data-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.0.0</td> <td> The following entries were added in the returned array: <em>mode</em>, <em>seekable</em>, and <em>uri</em>. </td> </tr> <tr> <td>4.3.0</td> <td> The following entries were added in the returned array: <em>stream_type</em>, <em>wrapper_type</em>, <em>wrapper_data</em>, and <em>filters</em>. </td> </tr> <tr> <td>4.3.0</td> <td> <span class="function"><a href="function.socket-get-status.html" class="function">socket_get_status()</a></span> is an alias for this function. Prior to PHP 4.3.0, it was used to retrieve the first four items, for <em class="emphasis">socket based streams only</em>. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.stream-get-meta-data-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4022"> <p><strong>Example #1 <span class="function"><strong>stream_get_meta_data()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$url </span><span style="color: #007700">= </span><span style="color: #DD0000">'http://www.example.com/'</span><span style="color: #007700">;<br /><br />if (!</span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$url</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">)) {<br /> </span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"Unable to open URL (</span><span style="color: #0000BB">$url</span><span style="color: #DD0000">)"</span><span style="color: #007700">, </span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$meta </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_get_meta_data</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$meta</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Array ( [wrapper_data] => Array ( [0] => HTTP/1.1 200 OK [1] => Server: Apache/2.2.3 (Red Hat) [2] => Last-Modified: Tue, 15 Nov 2005 13:24:10 GMT [3] => ETag: "b300b4-1b6-4059a80bfd280" [4] => Accept-Ranges: bytes [5] => Content-Type: text/html; charset=UTF-8 [6] => Set-Cookie: FOO=BAR; expires=Fri, 21-Dec-2012 12:00:00 GMT; path=/; domain=.example.com [6] => Connection: close [7] => Date: Fri, 16 Oct 2009 12:00:00 GMT [8] => Age: 1164 [9] => Content-Length: 438 ) [wrapper_type] => http [stream_type] => tcp_socket/ssl [mode] => r [unread_bytes] => 438 [seekable] => [uri] => http://www.example.com/ [timed_out] => [blocked] => 1 [eof] => ) </pre></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.stream-get-meta-data-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">This function does NOT work on sockets created by the <a href="ref.sockets.html" class="link">Socket extension</a>. </p> </p></blockquote> </div> <div class="refsect1 seealso" id="refsect1-function.stream-get-meta-data-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.get-headers.html" class="function" rel="rdfs-seeAlso">get_headers()</a> - Fetches all the headers sent by the server in response to a HTTP request</span></li> <li class="member"><a href="reserved.variables.httpresponseheader.html" class="link">$http_response_header</a></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.stream-get-line.html">stream_get_line</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.stream-get-transports.html">stream_get_transports</a></div> <div class="up"><a href="ref.stream.html">Stream Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>