IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
187 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PHP >= 5.3.0, PECL phar >= 2.0.0)

Phar::mountMount an external path or file to a virtual location within the phar archive


void Phar::mount ( string $pharpath , string $externalpath )

Much like the unix file system concept of mounting external devices to paths within the directory tree, Phar::mount() allows referring to external files and directories as if they were inside of an archive. This allows powerful abstraction such as referring to external configuration files as if they were inside the archive.



The internal path within the phar archive to use as the mounted path location. This must be a relative path within the phar archive, and must not already exist.


A path or URL to an external file or directory to mount within the phar archive

Return Values

No return. PharException is thrown on failure.


Throws PharException if any problems occur mounting the path.


Example #1 A Phar::mount() example

The following example shows accessing an external configuration file as if it were a path within a phar archive.

First, the code inside of a phar archive:

Phar::running(false) . '/config.xml'));

Next the external code used to mount the configuration file:

// first set up the association between the abstract config.xml
// and the actual one on disk
// now run the application
include '/path/to/archive.phar';

Another method is to put the mounting code inside the stub of the phar archive. Here is an example of setting up a default configuration file if no user configuration is specified:

// first set up the association between the abstract config.xml
// and the actual one on disk
if (defined('EXTERNAL_CONFIG')) {
    if (
file_exists(__DIR__ '/extra_config.xml')) {
Phar::mount('extra.xml'__DIR__ '/extra_config.xml');
} else {
Phar::mount('config.xml''phar://' __FILE__ '/default_config.xml');
Phar::mount('extra.xml''phar://' __FILE__ '/default_extra.xml');
// now run the application
include 'phar://' __FILE__ '/index.php';

...and the code externally to load this phar archive:

// now run the application
include '/path/to/archive.phar';

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP