<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/refs.compression.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'book.phar.php',
    1 => 'Phar',
    2 => 'Phar',
  ),
  'up' => 
  array (
    0 => 'refs.compression.php',
    1 => 'Erweiterungen zur Datenkompression und Archivierung',
  ),
  'prev' => 
  array (
    0 => 'function.lzf-optimized-for.php',
    1 => 'lzf_optimized_for',
  ),
  'next' => 
  array (
    0 => 'phar.setup.php',
    1 => 'Installation/Konfiguration',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/phar/book.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/book.phar.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="book.phar" class="book">
 
 <h1 class="title">Phar</h1>
 
 
 <div id="intro.phar" class="preface">
  <h1 class="title">Einführung</h1>
  <p class="para">
   The phar extension provides a way to put entire PHP applications into a single file
   called a &quot;phar&quot; (PHP Archive) for easy distribution and installation.
   In addition to providing this service, the phar extension also provides a file-format
   abstraction method for creating and manipulating tar and zip files through the
   <span class="classname"><a href="class.phardata.php" class="classname">PharData</a></span> class, much as
   PDO provides a unified interface for accessing different databases.  Unlike PDO,
   which cannot convert between different databases, Phar also can convert between tar,
   zip and phar file formats with a single line of code.  see
   <span class="function"><a href="phar.converttoexecutable.php" class="function">Phar::convertToExecutable()</a></span> for one example.
  </p>
  <p class="para">
   What is phar?  Phar archives are best characterized as a convenient way to group
   several files into a single file.  As such, a phar archive provides a way to
   distribute a complete PHP application in a single file and run it from that file
   without the need to extract it to disk.  Additionally, phar archives can be
   executed by PHP as easily as any other file, both on the commandline and from
   a web server.  Phar is kind of like a thumb drive for PHP applications.
  </p>
  <p class="para">
   Phar implements this functionality through a <a href="book.stream.php" class="link">Stream
   Wrapper</a>.  Normally, to use an external file within a PHP script, you
   would use <span class="function"><a href="function.include.php" class="function">include</a></span>:
  </p>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Beispiel #1 Using an external file</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /> </span><span style="color: #007700">include </span><span style="color: #DD0000">'/path/to/external/file.php'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   PHP can be thought of as actually translating
   <code class="literal">/path/to/external/file.php</code> into a
   stream wrapper as <code class="literal">file:///path/to/external/file.php</code>, and under
   the hood it does in fact use the plain file stream wrapper stream functions to
   access all local files.
  </p>
  <p class="para">
   To use a file named <code class="literal">file.php</code> contained with a phar archive
   <code class="literal">/path/to/myphar.phar</code>,
   the syntax is very similar to the <code class="literal">file://</code> syntax above.
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Beispiel #2 Using a file within a phar archive</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /> </span><span style="color: #007700">include </span><span style="color: #DD0000">'phar:///path/to/myphar.phar/file.php'</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   In fact, one can treat a phar archive exactly as if it were an external disk, using
   any of <span class="function"><a href="function.fopen.php" class="function">fopen()</a></span>-related functions, <span class="function"><a href="function.opendir.php" class="function">opendir()</a></span> and
   <span class="function"><a href="function.mkdir.php" class="function">mkdir()</a></span>-related functions to read, change, or create new files
   and directories within the phar archive.  This allows complete PHP applications
   to be distributed in a single file and run directly from that file.
  </p>
  <p class="para">
   The most common usage for a phar archive is to distribute a complete application
   in a single file.  For instance, the PEAR Installer that is bundled with PHP
   versions is distributed as a phar archive.  To use a phar archive distributed
   in this way, the archive can be executed on the command-line or via a web server.
  </p>
  <p class="para">
   Phar archives can be distributed as <code class="literal">tar</code> archives,
   <code class="literal">zip</code> archives, or as the custom <code class="literal">phar</code> file format
   designed specifically for the phar extension.  Each file format has advantages
   and disadvantages.  The tar and zip file formats can be read or extracted by any
   third-party tool that can read the format, but require the phar extension in order to
   run with PHP.  The phar file format is customized and unique to the phar extension,
   and can only be created by the phar extension or the PEAR package
   <a href="https://pear.php.net/package/PHP_Archive" class="link external">&raquo;&nbsp;PHP_Archive</a>, but has the
   advantage that applications created in this format will run even if the phar
   extension is not enabled.
  </p>
  <p class="para">
   In other words, even with the phar extension disabled, one can execute or include
   a phar-based archive.  Accessing individual files within a phar archive is only
   possible with the phar extension unless the phar archive was created by PHP_Archive.
  </p>
  <p class="para">
   The phar extension is also capable of converting a phar archive from tar to zip or
   to phar file format in a single command:
  </p>
  <p class="para">
   <div class="example" id="example-3">
    <p><strong>Beispiel #3 Converting a phar archive from phar to tar file format</strong></p>
    <div class="example-contents">
     <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /> $phar </span><span style="color: #007700">= new </span><span style="color: #0000BB">Phar</span><span style="color: #007700">(</span><span style="color: #DD0000">'myphar.phar'</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">$pgz </span><span style="color: #007700">= </span><span style="color: #0000BB">$phar</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">convertToExecutable</span><span style="color: #007700">(</span><span style="color: #0000BB">Phar</span><span style="color: #007700">::</span><span style="color: #0000BB">TAR</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">); </span><span style="color: #FF8000">// makes myphar.phar.tar.gz<br /> </span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Phar can compress individual files or an entire archive
   using <a href="book.zlib.php" class="link">gzip</a> compression or
   <a href="book.bzip2.php" class="link">bzip2</a> compression, and can verify archive
   integrity automatically through the use of MD5, SHA-1, SHA-256 or SHA-512
   signatures.
  </p>
  <p class="para">
   Lastly, the Phar extension is security-conscious, and disables write access
   to executable phar archives by default, and requires system-level disabling of the
   <code class="literal">phar.readonly</code> php.ini setting in order to create or
   modify phar archives.  Normal tar and zip archives without an executable stub
   can always be created or modified using the <span class="classname"><a href="class.phardata.php" class="classname">PharData</a></span> class.
  </p>
  <p class="para">
   If you are creating applications for distribution, you will want to read
   <a href="phar.creating.php" class="link">How to create Phar Archives</a>.  If you want
   more information on the differences between the three file formats that phar supports,
   you should read <a href="phar.fileformat.php" class="link">Phar, Tar and Zip</a>.
  </p>
  <p class="para">
   If you are using phar applications, there are helpful tips in
   <a href="phar.using.php" class="link">How to use Phar Archives</a>.
  </p>
  <p class="para">
   The word <code class="literal">phar</code> is a portmanteau of <code class="literal">PHP</code> and
   <code class="literal">Archive</code> and is based loosely
   on the <code class="literal">jar</code> (Java Archive) familiar to Java developers.
  </p>
  <p class="para">
   The implementation for Phar archives is based on the PEAR package
   <a href="https://pear.php.net/package/PHP_Archive" class="link external">&raquo;&nbsp;PHP_Archive</a>, and
   the implementation details are similar, although the Phar extension
   is much more powerful.  In addition, the Phar extension allows most PHP
   applications to be run unmodified while PHP_Archive-based phar archives
   often require extensive modification in order to work.
  </p>
 </div>
 
 
 







 




 





 





 





 







 




 




 





<ul class="chunklist chunklist_book"><li><a href="phar.setup.php">Installation/Konfiguration</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="phar.requirements.php">Anforderungen</a></li><li><a href="phar.installation.php">Installation</a></li><li><a href="phar.configuration.php">Laufzeit-Konfiguration</a></li><li><a href="phar.resources.php">Ressource-Typen</a></li></ul></li><li><a href="phar.constants.php">Vordefinierte Konstanten</a></li><li><a href="phar.using.php">Using Phar Archives</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="phar.using.intro.php">Using Phar Archives: Introduction</a></li><li><a href="phar.using.stream.php">Using Phar Archives: the phar stream wrapper</a></li><li><a href="phar.using.object.php">Using Phar Archives: the Phar and PharData class</a></li></ul></li><li><a href="phar.creating.php">Creating Phar Archives</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="phar.creating.intro.php">Creating Phar Archives: Introduction</a></li></ul></li><li><a href="phar.fileformat.php">What makes a phar a phar and not a tar or a zip?</a><ul class="chunklist chunklist_book chunklist_children"><li><a href="phar.fileformat.ingredients.php">Ingredients of all Phar archives, independent of file format</a></li><li><a href="phar.fileformat.stub.php">Phar file stub</a></li><li><a href="phar.fileformat.comparison.php">Head-to-head comparison of Phar, Tar and Zip</a></li><li><a href="phar.fileformat.tar.php">Tar-based phars</a></li><li><a href="phar.fileformat.zip.php">Zip-based phars</a></li><li><a href="phar.fileformat.phar.php">Phar File Format</a></li><li><a href="phar.fileformat.flags.php">Global Phar bitmapped flags</a></li><li><a href="phar.fileformat.manifestfile.php">Phar manifest file entry definition</a></li><li><a href="phar.fileformat.signature.php">Phar Signature format</a></li></ul></li><li><a href="class.phar.php">Phar</a> — Die Klasse Phar<ul class="chunklist chunklist_book chunklist_children"><li><a href="phar.addemptydir.php">Phar::addEmptyDir</a> — Add an empty directory to the phar archive</li><li><a href="phar.addfile.php">Phar::addFile</a> — Add a file from the filesystem to the phar archive</li><li><a href="phar.addfromstring.php">Phar::addFromString</a> — Add a file from a string to the phar archive</li><li><a href="phar.apiversion.php">Phar::apiVersion</a> — Returns the api version</li><li><a href="phar.buildfromdirectory.php">Phar::buildFromDirectory</a> — Construct a phar archive from the files within a directory</li><li><a href="phar.buildfromiterator.php">Phar::buildFromIterator</a> — Construct a phar archive from an iterator</li><li><a href="phar.cancompress.php">Phar::canCompress</a> — Returns whether phar extension supports compression using either zlib or bzip2</li><li><a href="phar.canwrite.php">Phar::canWrite</a> — Returns whether phar extension supports writing and creating phars</li><li><a href="phar.compress.php">Phar::compress</a> — Compresses the entire Phar archive using Gzip or Bzip2 compression</li><li><a href="phar.compressfiles.php">Phar::compressFiles</a> — Compresses all files in the current Phar archive</li><li><a href="phar.construct.php">Phar::__construct</a> — Construct a Phar archive object</li><li><a href="phar.converttodata.php">Phar::convertToData</a> — Convert a phar archive to a non-executable tar or zip file</li><li><a href="phar.converttoexecutable.php">Phar::convertToExecutable</a> — Convert a phar archive to another executable phar archive file format</li><li><a href="phar.copy.php">Phar::copy</a> — Copy a file internal to the phar archive to another new file within the phar</li><li><a href="phar.count.php">Phar::count</a> — Returns the number of entries (files) in the Phar archive</li><li><a href="phar.createdefaultstub.php">Phar::createDefaultStub</a> — Create a phar-file format specific stub</li><li><a href="phar.decompress.php">Phar::decompress</a> — Decompresses the entire Phar archive</li><li><a href="phar.decompressfiles.php">Phar::decompressFiles</a> — Decompresses all files in the current Phar archive</li><li><a href="phar.delmetadata.php">Phar::delMetadata</a> — Deletes the global metadata of the phar</li><li><a href="phar.delete.php">Phar::delete</a> — Delete a file within a phar archive</li><li><a href="phar.destruct.php">Phar::__destruct</a> — Destructs a Phar archive object</li><li><a href="phar.extractto.php">Phar::extractTo</a> — Extract the contents of a phar archive to a directory</li><li><a href="phar.getalias.php">Phar::getAlias</a> — Get the alias for Phar</li><li><a href="phar.getmetadata.php">Phar::getMetadata</a> — Returns phar archive meta-data</li><li><a href="phar.getmodified.php">Phar::getModified</a> — Return whether phar was modified</li><li><a href="phar.getpath.php">Phar::getPath</a> — Get the real path to the Phar archive on disk</li><li><a href="phar.getsignature.php">Phar::getSignature</a> — Return MD5/SHA1/SHA256/SHA512/OpenSSL signature of a Phar archive</li><li><a href="phar.getstub.php">Phar::getStub</a> — Return the PHP loader or bootstrap stub of a Phar archive</li><li><a href="phar.getsupportedcompression.php">Phar::getSupportedCompression</a> — Return array of supported compression algorithms</li><li><a href="phar.getsupportedsignatures.php">Phar::getSupportedSignatures</a> — Return array of supported signature types</li><li><a href="phar.getversion.php">Phar::getVersion</a> — Return version info of Phar archive</li><li><a href="phar.hasmetadata.php">Phar::hasMetadata</a> — Returns whether phar has global meta-data</li><li><a href="phar.interceptfilefuncs.php">Phar::interceptFileFuncs</a> — Instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions</li><li><a href="phar.isbuffering.php">Phar::isBuffering</a> — Used to determine whether Phar write operations are being buffered, or are flushing directly to disk</li><li><a href="phar.iscompressed.php">Phar::isCompressed</a> — Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)</li><li><a href="phar.isfileformat.php">Phar::isFileFormat</a> — Returns true if the phar archive is based on the tar/phar/zip file format depending on the parameter</li><li><a href="phar.isvalidpharfilename.php">Phar::isValidPharFilename</a> — Returns whether the given filename is a valid phar filename</li><li><a href="phar.iswritable.php">Phar::isWritable</a> — Returns true if the phar archive can be modified</li><li><a href="phar.loadphar.php">Phar::loadPhar</a> — Loads any phar archive with an alias</li><li><a href="phar.mapphar.php">Phar::mapPhar</a> — Reads the currently executed file (a phar) and registers its manifest</li><li><a href="phar.mount.php">Phar::mount</a> — Mount an external path or file to a virtual location within the phar archive</li><li><a href="phar.mungserver.php">Phar::mungServer</a> — Defines a list of up to 4 $_SERVER variables that should be modified for execution</li><li><a href="phar.offsetexists.php">Phar::offsetExists</a> — Determines whether a file exists in the phar</li><li><a href="phar.offsetget.php">Phar::offsetGet</a> — Gets a PharFileInfo object for a specific file</li><li><a href="phar.offsetset.php">Phar::offsetSet</a> — Set the contents of an internal file to those of an external file</li><li><a href="phar.offsetunset.php">Phar::offsetUnset</a> — Remove a file from a phar</li><li><a href="phar.running.php">Phar::running</a> — Returns the full path on disk or full phar URL to the currently executing Phar archive</li><li><a href="phar.setalias.php">Phar::setAlias</a> — Set the alias for the Phar archive</li><li><a href="phar.setdefaultstub.php">Phar::setDefaultStub</a> — Used to set the PHP loader or bootstrap stub of a Phar archive to the default loader</li><li><a href="phar.setmetadata.php">Phar::setMetadata</a> — Sets phar archive meta-data</li><li><a href="phar.setsignaturealgorithm.php">Phar::setSignatureAlgorithm</a> — Set the signature algorithm for a phar and apply it</li><li><a href="phar.setstub.php">Phar::setStub</a> — Used to set the PHP loader or bootstrap stub of a Phar archive</li><li><a href="phar.startbuffering.php">Phar::startBuffering</a> — Start buffering Phar write operations, do not modify the Phar object on disk</li><li><a href="phar.stopbuffering.php">Phar::stopBuffering</a> — Stop buffering write requests to the Phar archive, and save changes to disk</li><li><a href="phar.unlinkarchive.php">Phar::unlinkArchive</a> — Completely remove a phar archive from disk and from memory</li><li><a href="phar.webphar.php">Phar::webPhar</a> — Routes a request from a web browser to an internal file within the phar archive</li></ul></li><li><a href="class.phardata.php">PharData</a> — The PharData class<ul class="chunklist chunklist_book chunklist_children"><li><a href="phardata.addemptydir.php">PharData::addEmptyDir</a> — Add an empty directory to the tar/zip archive</li><li><a href="phardata.addfile.php">PharData::addFile</a> — Add a file from the filesystem to the tar/zip archive</li><li><a href="phardata.addfromstring.php">PharData::addFromString</a> — Add a file from a string to the tar/zip archive</li><li><a href="phardata.buildfromdirectory.php">PharData::buildFromDirectory</a> — Construct a tar/zip archive from the files within a directory</li><li><a href="phardata.buildfromiterator.php">PharData::buildFromIterator</a> — Construct a tar or zip archive from an iterator</li><li><a href="phardata.compress.php">PharData::compress</a> — Compresses the entire tar/zip archive using Gzip or Bzip2 compression</li><li><a href="phardata.compressfiles.php">PharData::compressFiles</a> — Compresses all files in the current tar/zip archive</li><li><a href="phardata.construct.php">PharData::__construct</a> — Construct a non-executable tar or zip archive object</li><li><a href="phardata.converttodata.php">PharData::convertToData</a> — Convert a phar archive to a non-executable tar or zip file</li><li><a href="phardata.converttoexecutable.php">PharData::convertToExecutable</a> — Convert a non-executable tar/zip archive to an executable phar archive</li><li><a href="phardata.copy.php">PharData::copy</a> — Copy a file internal to the tar/zip archive to another new file within the same archive</li><li><a href="phardata.decompress.php">PharData::decompress</a> — Decompresses the entire Phar archive</li><li><a href="phardata.decompressfiles.php">PharData::decompressFiles</a> — Decompresses all files in the current zip archive</li><li><a href="phardata.delmetadata.php">PharData::delMetadata</a> — Deletes the global metadata of a zip archive</li><li><a href="phardata.delete.php">PharData::delete</a> — Delete a file within a tar/zip archive</li><li><a href="phardata.destruct.php">PharData::__destruct</a> — Destructs a non-executable tar or zip archive object</li><li><a href="phardata.extractto.php">PharData::extractTo</a> — Extract the contents of a tar/zip archive to a directory</li><li><a href="phardata.iswritable.php">PharData::isWritable</a> — Returns true if the tar/zip archive can be modified</li><li><a href="phardata.offsetset.php">PharData::offsetSet</a> — Set the contents of a file within the tar/zip to those of an external file or string</li><li><a href="phardata.offsetunset.php">PharData::offsetUnset</a> — Remove a file from a tar/zip archive</li><li><a href="phardata.setalias.php">PharData::setAlias</a> — Dummy function (Phar::setAlias is not valid for PharData)</li><li><a href="phardata.setdefaultstub.php">PharData::setDefaultStub</a> — Dummy function (Phar::setDefaultStub is not valid for PharData)</li><li><a href="phardata.setmetadata.php">PharData::setMetadata</a> — Sets phar archive meta-data</li><li><a href="phardata.setsignaturealgorithm.php">PharData::setSignatureAlgorithm</a> — Set the signature algorithm for a phar and apply it</li><li><a href="phardata.setstub.php">PharData::setStub</a> — Dummy function (Phar::setStub is not valid for PharData)</li></ul></li><li><a href="class.pharfileinfo.php">PharFileInfo</a> — The PharFileInfo class<ul class="chunklist chunklist_book chunklist_children"><li><a href="pharfileinfo.chmod.php">PharFileInfo::chmod</a> — Sets file-specific permission bits</li><li><a href="pharfileinfo.compress.php">PharFileInfo::compress</a> — Compresses the current Phar entry with either zlib or bzip2 compression</li><li><a href="pharfileinfo.construct.php">PharFileInfo::__construct</a> — Construct a Phar entry object</li><li><a href="pharfileinfo.decompress.php">PharFileInfo::decompress</a> — Decompresses the current Phar entry within the phar</li><li><a href="pharfileinfo.delmetadata.php">PharFileInfo::delMetadata</a> — Deletes the metadata of the entry</li><li><a href="pharfileinfo.destruct.php">PharFileInfo::__destruct</a> — Destructs a Phar entry object</li><li><a href="pharfileinfo.getcrc32.php">PharFileInfo::getCRC32</a> — Returns CRC32 code or throws an exception if CRC has not been verified</li><li><a href="pharfileinfo.getcompressedsize.php">PharFileInfo::getCompressedSize</a> — Returns the actual size of the file (with compression) inside the Phar archive</li><li><a href="pharfileinfo.getcontent.php">PharFileInfo::getContent</a> — Get the complete file contents of the entry</li><li><a href="pharfileinfo.getmetadata.php">PharFileInfo::getMetadata</a> — Returns file-specific meta-data saved with a file</li><li><a href="pharfileinfo.getpharflags.php">PharFileInfo::getPharFlags</a> — Returns the Phar file entry flags</li><li><a href="pharfileinfo.hasmetadata.php">PharFileInfo::hasMetadata</a> — Returns the metadata of the entry</li><li><a href="pharfileinfo.iscrcchecked.php">PharFileInfo::isCRCChecked</a> — Returns whether file entry has had its CRC verified</li><li><a href="pharfileinfo.iscompressed.php">PharFileInfo::isCompressed</a> — Returns whether the entry is compressed</li><li><a href="pharfileinfo.setmetadata.php">PharFileInfo::setMetadata</a> — Sets file-specific meta-data saved with a file</li></ul></li><li><a href="class.pharexception.php">PharException</a> — The PharException class</li></ul></div><?php manual_footer($setup); ?>