Manuel PHP
Précédent |  | Suivant

# Phar->commit

(no version information, might be only in CVS)

Phar->commit -- End a Phar modification transaction by writing the Phar archive to disk

## Description

void Phar->commit ( void )

Although technically unnecessary, the begin() method can provide a significant performance boost when creating or modifying a Phar archive with a large number of files. Ordinarily, every time a file within a Phar archive is created or modified in any way, the entire Phar archive will be recreated with the changes. In this way, the archive will be up-to-date with the activity performed on it.

However, this can be unnecessary when simply creating a new Phar archive, when it would make more sense to write the entire archive out at once. Similarly, it is often necessary to make a series of changes and to ensure that they all are possible before making any changes on disk, similar to the relational database concept of transactions. The begin()/commit() pair of methods is provided for this purpose.

Phar transactions are per-archive, a transaction active on the `foo.phar` Phar archive does not affect changes to the `bar.phar` Phar archive.

## Erreurs / Exceptions

PharException is thrown if any problems are encountered flushing changes to disk.

## Exemples

Exemple 1. A Phar->commit() example

`<?php
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
$p['file1.txt'] = 'hi';
$p->commit();
var_dump($p->getStub());
$p->setStub("<?php
function __autoload(\$class)
{
include 'phar://' . str_replace('_', '/', \$class);
}
Phar::mapPhar('brandnewphar.phar');
include 'phar://brandnewphar.phar/startup.php';
__HALT_COMPILER();");
$p->commit();
var_dump($p->getStub());
?>`

L'exemple ci-dessus va afficher :

    string(24) "<?php __HALT_COMPILER();"
    string(195) "<?php
    function __autoload($class)
    {
        include 'phar://' . str_replace('_', '/', $class);
    }
    Phar::mapPhar('brandnewphar.phar');
    include 'phar://brandnewphar.phar/startup.php';
    __HALT_COMPILER();"

## Voir aussi

Phar->begin()

Précédent | Sommaire | Suivant
Phar::canWrite | Niveau supérieur | Phar->compressAllFilesBZIP2