<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc'; $TOC = array(); $TOC_DEPRECATED = array(); $PARENTS = array(); include_once dirname(__FILE__) ."/toc/phar.using.inc"; $setup = array ( 'home' => array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'phar.using.stream.php', 1 => 'Using Phar Archives: the phar stream wrapper', ), 'up' => array ( 0 => 'phar.using.php', 1 => 'Using Phar Archives', ), 'prev' => array ( 0 => 'phar.using.intro.php', 1 => 'Using Phar Archives: Introduction', ), 'next' => array ( 0 => 'phar.using.object.php', 1 => 'Using Phar Archives: the Phar and PharData class', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/phar/using.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?> <div id="phar.using.stream" class="section"> <h2 class="title">Using Phar Archives: the phar stream wrapper</h2> <p class="para"> The Phar stream wrapper fully supports <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span> for read and write (not append), <span class="function"><a href="function.unlink.php" class="function">unlink()</a></span>, <span class="function"><a href="function.stat.php" class="function">stat()</a></span>, <span class="function"><a href="function.fstat.php" class="function">fstat()</a></span>, <span class="function"><a href="function.fseek.php" class="function">fseek()</a></span>, <span class="function"><a href="function.rename.php" class="function">rename()</a></span> and directory stream operations <span class="function"><a href="function.opendir.php" class="function">opendir()</a></span> and <span class="function"><a href="function.rmdir.php" class="function">rmdir()</a></span> and <span class="function"><a href="function.mkdir.php" class="function">mkdir()</a></span>. </p> <p class="para"> Individual file compression and per-file metadata can also be manipulated in a Phar archive using stream contexts: </p> <p class="para"> <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$context </span><span style="color: #007700">= </span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'phar' </span><span style="color: #007700">=><br /> array(</span><span style="color: #DD0000">'compress' </span><span style="color: #007700">=> </span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">GZ</span><span style="color: #007700">)),<br /> array(</span><span style="color: #DD0000">'metadata' </span><span style="color: #007700">=> array(</span><span style="color: #DD0000">'user' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'cellog'</span><span style="color: #007700">)));<br /></span><span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'phar://my.phar/somefile.php'</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> The <code class="literal">phar</code> stream wrapper does not operate on remote files, and cannot operate on remote files, and so is allowed even when the <a href="filesystem.configuration.php#ini.allow-url-fopen" class="link">allow_url_fopen</a> and <a href="filesystem.configuration.php#ini.allow-url-include" class="link">allow_url_include</a> INI options are disabled. </p> <p class="para"> Although it is possible to create phar archives from scratch just using stream operations, it is best to use the functionality built into the Phar class. The stream wrapper is best used for read-only operations. </p> </div><?php manual_footer($setup); ?>